Skip to content

Commit 14e2569

Browse files
committed
add js soultion for leetcode 20
1 parent 92773a8 commit 14e2569

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ LeetCode
392392
|23|[Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/)| |Hard|
393393
|22|[Generate Parentheses](https://leetcode.com/problems/generate-parentheses/)| [js](./algorithms/generateParentheses/generateParentheses.js) |Medium|
394394
|21|[Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/)| [java](./algorithm/mergeTwoSortedLists/Solution.java) |Easy|
395-
|20|[Valid Parentheses](https://leetcode.com/problems/valid-parentheses/)| |Easy|
395+
|20|[Valid Parentheses](https://leetcode.com/problems/valid-parentheses/)| [js](./algorithms/validParentheses/validParentheses.js) |Easy|
396396
|19|[Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/)| [js](./algorithms/removeNthNodeFromEndOfList/removeNthNodeFromEndOfList.js) |Easy|
397397
|18|[4Sum](https://leetcode.com/problems/4sum/)| [js](./algorithms/4Sum/4Sum.js) |Medium|
398398
|17|[Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)| |Medium|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var isValid = function(s) {
2+
const stack = [], map = {
3+
")": "(",
4+
"]": "[",
5+
"}": "{",
6+
7+
};
8+
for (str of s) {
9+
if (str => ["(", "[", "{"].includes(str)) {
10+
stack.push(str)
11+
} else {
12+
if (stack[stack.length - 1] === map[str]) {
13+
stack.pop();
14+
} else {
15+
return false;
16+
}
17+
}
18+
}
19+
return stack.length === 0;
20+
};

0 commit comments

Comments
 (0)