728x90
https://programmers.co.kr/learn/courses/30/lessons/42585
import java.util.Stack;
class Solution {
public static int solution(String arrangement) {
int answer = 0;
Stack<Character> stack = new Stack<>();
for (int i = 0; i < arrangement.length(); i++) {
if (arrangement.charAt(i) == '(')
stack.add(arrangement.charAt(i));
else {
stack.pop();
if (arrangement.charAt(i - 1) == '(')
answer += stack.size();
else
answer++;
}
}
return answer;
}
}
문제 난이도는 높지 않은데, 헤맸다.
심지어 대학교 졸업하고 풀어봤던 문제인데...
728x90