programmers_올바른 괄호_java
2023. 2. 27. 10:20ㆍAlgorithm/Programmers
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/12909
import java.util.*;
class Solution {
boolean solution(String s) {
boolean answer = true;
Stack<Character> stack = new Stack<>();
int size = s.length();
for(int i = 0; i<size; i++){
if(s.charAt(i) == '('){
stack.push('(');
}else if(s.charAt(i) == ')'){
if(!stack.isEmpty()){
stack.pop();
}else{
answer = false;
break;
}
}
}
if(!stack.isEmpty()){
answer = false;
}
return answer;
}
}
'Algorithm > Programmers' 카테고리의 다른 글
programmers_네트워크_java (0) | 2023.02.27 |
---|---|
programmers_최솟값 만들기_java (0) | 2023.02.27 |
programmers_JadenCase 문자열 만들기_java (0) | 2023.02.27 |
programmers_최댓값과 최솟값_java (0) | 2023.02.24 |
Programmers_이중우선순위큐_java (0) | 2023.02.23 |