- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNo20.java
25 lines (22 loc) · 518 Bytes
/
No20.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
packageAlgorithm.leetcode.String;
importjava.util.Stack;
publicclassNo20 {
publicbooleanisValid(Strings) {
Stack<Character> stack = newStack<Character>();
for (charc : s.toCharArray()) {
if (c == '(') {
stack.push(')');
} elseif (c == '{') {
stack.push('}');
} elseif (c == '[') {
stack.push(']');
} elseif (stack.isEmpty() || stack.pop() != c) {
returnfalse;
}
}
returnstack.isEmpty();
}
publicstaticvoidmain(String[] args) {
System.out.println();
}
}