We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0c9831d commit 8cdac46Copy full SHA for 8cdac46
README.md
@@ -256,6 +256,15 @@ class Solution:
256
def isValid(self, s: str) -> bool:
257
while any(('()' in s, '[]' in s, '{}' in s)): s = s.replace('()', '').replace('[]', '').replace('{}', '')
258
return not s
259
+
260
+# 国际站上有一种写法是这样的,相比于上面,下面的写法更加优雅(好理解)一点
261
+class Solution:
262
+ def isValid(self, s: str) -> bool:
263
+ while s:
264
+ l = len(s)
265
+ s = s.replace('()', '').replace('[]', '').replace('{}', '')
266
+ if l == len(s): break
267
+ return not s
268
```
269
- 不断删除有效括号直到不能删除,思路简单效率低。另外,stack的方法也很简单,而且快多了。
270
@@ -264,7 +273,7 @@ class Solution:
273
274
stack, d = [], {'{': '}', '[': ']', '(': ')'}
275
for p in s:
- if p in '{[(':
276
+ if p in d:
277
stack += [p];
278
elif not (stack and d[stack.pop()] == p):
279
return False
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments