Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions java/0020-valid-parentheses.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ public boolean isValid(String s) {
stack.isEmpty() &&
(s.charAt(i) == ')' || s.charAt(i) == '}' || s.charAt(i) == ']')
) return false; else {
if (!stack.isEmpty()) {
if (
stack.peek() == '(' && s.charAt(i) == ')'
s.charAt(i) == ')' && stack.peek() == '('
) stack.pop(); else if (
stack.peek() == '{' && s.charAt(i) == '}'
s.charAt(i) == '}' && stack.peek() == '{'
) stack.pop(); else if (
stack.peek() == '[' && s.charAt(i) == ']'
s.charAt(i) == ']' && stack.peek() == '['
) stack.pop(); else stack.add(s.charAt(i));
} else stack.add(s.charAt(i));
}
}
return stack.isEmpty();
Expand Down