Skip to content

Commit d8bf30d

Browse files
committed
update
1 parent 6b44b3b commit d8bf30d

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

.prettierrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ LeetCode Problems' Solutions in JavaScript
1515
9. [第一个错误的版本](./algorithms/easy/solution/solution.js)
1616
10. [两个数组的交集 II](./algorithms/easy/intersect/intersect.js)
1717
11. [汉明距离](./algorithms/easy/hammingDistance/hammingDistance.js)
18+
12. [汉明距离](./algorithms/easy/isValid/isValid.js)
1819

1920
## medium
2021

algorithms/easy/isValid/isValid.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
};

0 commit comments

Comments
 (0)