문제 링크
https://programmers.co.kr/learn/courses/30/lessons/76502#
문제 풀이
코드
import java.util.*;
class Solution {
public int solution(String s) {
int answer = 0;
for(int i=0; i<s.length(); i++){
Stack<String> st = new Stack();
s = s.substring(1,s.length())+s.substring(0,1);
for(int j=0; j<s.length(); j++){
String word = s.substring(j,j+1);
if(st.isEmpty()){
st.push(word);
continue;
}
if(word.equals(")") && st.peek().equals("(")){
st.pop();
}else if(word.equals("}") && st.peek().equals("{")){
st.pop();
}else if(word.equals("]") && st.peek().equals("[")){
st.pop();
}else{
st.push(word);
}
}
if(st.isEmpty()){
answer++;
}
}
return answer;
}
}