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 0eb61a5 commit 64b9363Copy full SHA for 64b9363
problems/0020.有效的括号.md
@@ -271,6 +271,23 @@ var isValid = function (s) {
271
}
272
return stack.length === 0;
273
};
274
+// 简化版本
275
+var isValid = function(s) {
276
+ const stack = [],
277
+ map = {
278
+ "(":")",
279
+ "{":"}",
280
+ "[":"]"
281
+ };
282
+ for(const x of s) {
283
+ if(x in map) {
284
+ stack.push(x);
285
+ continue;
286
287
+ if(map[stack.pop()] !== x) return false;
288
+ }
289
+ return !stack.length;
290
+};
291
```
292
293
0 commit comments