https://school.programmers.co.kr/learn/courses/30/lessons/12909
์ค๋๋ง์ Stack๋ง ์จ์ ์ฐ์ตํ๋ฏํ๋ค.
import java.util.*;
class Solution {
boolean solution(String s) {
boolean answer = true;
Stack<Character> stack = new Stack<>();
for(int i=0; i<s.length(); i++){
if(s.charAt(i) == '(') stack.add(s.charAt(i));
else {
if(stack.isEmpty()) answer = false;
else{
stack.pop();
}
}
}
if(!stack.empty()) answer=false;
return answer;
}
}
'๐ ์ฝ๋ฉํ ์คํธ > ๋ฐฑ์ค & ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 2 : ์ซ์์ ํํ (0) | 2023.04.02 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 2 : ์ด์ง ๋ณํ ๋ฐ๋ณตํ๊ธฐ (0) | 2023.03.31 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA] Level 2 : ์ต์๊ฐ ๋ง๋ค๊ธฐ (0) | 2023.03.27 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 2 : JadenCase ๋ฌธ์์ด ๋ง๋ค๊ธฐ (0) | 2023.03.26 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 2 : ์ต๋๊ฐ๊ณผ ์ต์๊ฐ (0) | 2023.03.17 |