Skip to content

Commit

Permalink
feat: update 20-is-valid
Browse files Browse the repository at this point in the history
  • Loading branch information
YanceyOfficial committed Sep 1, 2023
1 parent d8ab80d commit db20b75
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions leetcode-docs/easy/20-is-valid.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ var isValid = function (s) {
} else {
const top = stack[stack.length - 1]

if (top === '{' && s[i] === '}') stack.pop()
else if (top === '[' && s[i] === ']') stack.pop()
else if (top === '(' && s[i] === ')') stack.pop()
if (top === '{' && ch === '}') stack.pop()
else if (top === '[' && ch === ']') stack.pop()
else if (top === '(' && ch === ')') stack.pop()
else return false
}
}
Expand Down
3 changes: 1 addition & 2 deletions leetcode-docs/hard/32-longest-valid-parentheses.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ var longestValidParentheses = function (s) {

let max = 0
for (let i = 0; i < n; i++) {
const curr = s[i]
if (curr === '(') {
if (s[i] === '(') {
stack.push(i)
} else {
stack.pop()
Expand Down
6 changes: 3 additions & 3 deletions src/leetcode/javascript/easy/20.有效的括号.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ var isValid = function (s) {
stack.push(ch)
} else {
const top = stack[stack.length - 1]
if (top === '{' && s[i] === '}') stack.pop()
else if (top === '[' && s[i] === ']') stack.pop()
else if (top === '(' && s[i] === ')') stack.pop()
if (top === '{' && ch === '}') stack.pop()
else if (top === '[' && ch === ']') stack.pop()
else if (top === '(' && ch === ')') stack.pop()
else return false
}
}
Expand Down

0 comments on commit db20b75

Please sign in to comment.