File tree 3 files changed +38
-0
lines changed
3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "printWidth": 100,
3
+ "tabWidth": 2,
4
+ "useTabs": false,
5
+ "semi": true,
6
+ "singleQuote": true,
7
+ "jsxBracketSameLine": true,
8
+ "bracketSpacing": true,
9
+ "trailingComma": "es5"
10
+ }
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ LeetCode Problems' Solutions in JavaScript
15
15
9 . [ 第一个错误的版本] ( ./algorithms/easy/solution/solution.js )
16
16
10 . [ 两个数组的交集 II] ( ./algorithms/easy/intersect/intersect.js )
17
17
11 . [ 汉明距离] ( ./algorithms/easy/hammingDistance/hammingDistance.js )
18
+ 12 . [ 汉明距离] ( ./algorithms/easy/isValid/isValid.js )
18
19
19
20
## medium
20
21
Original file line number Diff line number Diff line change
1
+ // description: https://leetcode-cn.com/explore/interview/card/top-interview-questions-easy/26/others/68/
2
+ // 有效的括号
3
+
4
+ var isValid = function ( s ) {
5
+ const charMap = {
6
+ ')' : '(' ,
7
+ ']' : '[' ,
8
+ '}' : '{' ,
9
+ } ;
10
+
11
+ const leftChars = [ '(' , '[' , '{' ] ;
12
+
13
+ const stash = [ ] ;
14
+
15
+ for ( const char of s ) {
16
+ if ( leftChars . indexOf ( char ) !== - 1 ) {
17
+ stash . push ( char ) ;
18
+ continue ;
19
+ }
20
+ const leftChar = charMap [ char ] ;
21
+ if ( leftChar !== stash [ stash . length - 1 ] ) {
22
+ return false ;
23
+ }
24
+ stash . pop ( ) ;
25
+ }
26
+ return stash . length === 0 ;
27
+ } ;
You can’t perform that action at this time.
0 commit comments