인프런 커뮤니티 질문&답변
테스트 케이스를 추가해야 할 거 같아요
해결된 질문
작성
·
389
0
채점사이트에서 해당 문제의 테스트 케이스 중에서 여는 괄호가 많은 케이스를 추가해야 할 거 같아요!
for문이 끝나고 stack이 비어있는 것을 체크 안하고 "YES"를 반환하도록 코드를 작성했는데 통과합니다!
테스트 케이스를 통과한 코드는 다음과 같아요
private static String solutionUseStack(final String parenthesis){
final Stack<Character> leftParenthesis = new Stack<>();
for (char c : parenthesis.toCharArray()){
if(c == '(')
leftParenthesis.push('(');
else{
if(leftParenthesis.empty())
return "NO";
else
leftParenthesis.pop();
}
}
return "YES";
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
final String parenthesis = sc.next();
// System.out.println(solution(parenthesis));
System.out.println(solutionUseStack(parenthesis));
}




