Notice
Recent Posts
Recent Comments
- Today
- Total
01-11 01:45
Tags
- CS
- BFS
- PS
- ๋ฌธ๋ฒ
- MST
- ์กธ์ ์ํ
- array
- ๋ค์ต์คํธ๋ผ
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- ์๋ฃ๊ตฌ์กฐ
- ๋ฒจ๋งํฌ๋
- leetcode
- ์์์ ๋ ฌ
- OOP
- dp
- ๊ทธ๋ฆฌ๋
- Algorithm
- pytorch
- ์ธํด
- ์๋ฐ
- java
- tree
- ์๋ฐ์์ ์
- ๋ฐฑ์๋
- database
- spring
- ๋ฐฑ์ค
- ๊ตฌํ
- Graph
- ํ๋ก๊ทธ๋๋จธ์ค
Link
Partially Committed
[์คํ/ํ] ์ฌ๋ฐ๋ฅธ ๊ดํธ (JAVA) ๋ณธ๋ฌธ
728x90
๋ฐ์ํ
SMALL
https://school.programmers.co.kr/learn/courses/30/lessons/12909
import java.io.IOException;
import java.util.Stack;
class Solution {
boolean solution(String s) throws IOException {
boolean answer = true;
Stack<Character> st = new Stack<>();
char[] arr = s.toCharArray();
for(int i = 0 ; i < s.length(); i++){
if(st.isEmpty()){
if(arr[i] == ')'){
return false;
}
st.push(arr[i]);
continue;
}
if(arr[i] == '('){
st.push(arr[i]); continue;
}
else{ // arr[i] == ')'
if(st.peek() == '(') st.pop();
else return false;
}
}
if(st.isEmpty()) answer = true;
else answer = false;
return answer;
}
}
728x90
๋ฐ์ํ
LIST
'๐ฅ Algorithm || ๋ฌธ์ ํ์ด > PS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[์ฐ์ ์์ํ] ํ๋ฆฐํฐ (์๋ฐ) (0) | 2022.09.04 |
---|---|
[ํ] ๊ธฐ๋ฅ๊ฐ๋ฐ (JAVA) (0) | 2022.09.03 |
[๋ฐฐ์ด] ๊ฐ์ ์ซ์๋ ์ซ์ด (JAVA) (0) | 2022.09.02 |
[์ ๋ ฌ] ๊ฐ์ฅ ํฐ ์ (JAVA) (0) | 2022.09.02 |
[์ ๋ ฌ] K ๋ฒ์งธ์ (JAVA) (0) | 2022.09.02 |
Comments