Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b8a77a9 commit 25530d9Copy full SHA for 25530d9
java/0020-valid-parentheses.java
@@ -8,15 +8,13 @@ public boolean isValid(String s) {
8
stack.isEmpty() &&
9
(s.charAt(i) == ')' || s.charAt(i) == '}' || s.charAt(i) == ']')
10
) return false; else {
11
- if (!stack.isEmpty()) {
12
if (
13
- stack.peek() == '(' && s.charAt(i) == ')'
+ s.charAt(i) == ')' && stack.peek() == '('
14
) stack.pop(); else if (
15
- stack.peek() == '{' && s.charAt(i) == '}'
+ s.charAt(i) == '}' && stack.peek() == '{'
16
17
- stack.peek() == '[' && s.charAt(i) == ']'
+ s.charAt(i) == ']' && stack.peek() == '['
18
) stack.pop(); else stack.add(s.charAt(i));
19
- } else stack.add(s.charAt(i));
20
}
21
22
return stack.isEmpty();
0 commit comments