Grind75
문제로
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| class Solution {
public boolean isValid(String s) {
Stack<Character> stack = new Stack<>();
for(int i = 0; i < s.length(); i++) {
if(s.charAt(i) == '(') {
stack.push(')');
} else if (s.charAt(i) =='{') {
stack.push('}');
} else if (s.charAt(i) == '[') {
stack.push(']');
} else {
if(stack.isEmpty()) return false;
char c = stack.pop();
if(c != s.charAt(i)) return false;
}
}
return stack.isEmpty();
}
}
|

document
1
2
3
4
5
| public E push(E item)
public E pop()
public E peek()
public boolean empty()
public int search(Object o)
|
이 문제는 Grind 169에서도 다뤘다: Grind 169 - Valid Parentheses