감사합니다..ㅎ.ㅎ
package courses30.lessons12909;
import java.util.Stack;
public class Solution {
boolean solution(String s) {
Stack<Character> stack = new Stack<>();
for (int i = 0; i < s.length(); i++) {
switch (s.charAt(i)) {
case '(':
stack.add(s.charAt(i));
break;
case ')':
if (stack.isEmpty()) {
return false;
}
if (stack.peek() == '(') {
stack.pop();
} else {
return false;
}
break;
}
}
return stack.isEmpty();
}
public static void main(String[] args) {
System.out.println(new Solution().solution("()()"));
}
}