프로그래머스 코딩테스트 연습문제 (올바른 괄호)
import java.util.Stack;
class Solution {
boolean solution(String s) {
Stack<Integer> sta = new Stack<>();
// [실행] 버튼을 누르면 출력 값을 볼 수 있습니다.
System.out.println(s);
for(int i = 0; i<s.length(); i++){
if(s.charAt(i)=='('){
sta.push(1);
}
else{
if(sta.empty()){
return false;
}
sta.pop();
}
}
return sta.empty();
}
}
댓글