Notice
Recent Posts
Recent Comments
Link
05-02 04:53
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- springboot
- Java
- 로드밸런스
- 클라우드 서비스 개발 #
- 맥북
- Gradle
- 우리FIS아카데미
- https
- 리눅스
- 우리FISA #
- 도메인
- 우리에프아이에스
- 우리FISA
- 우리FIS아카데미 #
- 맥OS
- M2
- K-디지털트레이닝
- 맥
- spring
- sts
- 클라우드 서비스 개발
- mysql
- 우리에프아이에스 #
- 글로벌소프트웨어캠퍼스
- dbeaver
- jdk
- route 53
- HTTP
- AWS
Archives
- Today
- Total
<<개발일지>>
[힌트 문제1-3] 스택 본문
백준 9012번 스택과 괄호
나는 Scanner 와 Stack으로 품
import java.util.Scanner;
import java.util.Stack;
// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for (int i = 0; i < T; i++) {
System.out.println(solve(in.next()));
}
}
public static String solve(String s) {
Stack<Character> stack = new Stack<>();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '(') {
stack.push(c);
} else if (stack.empty()) {
return "NO";
} else {
stack.pop();
}
}
if (stack.empty()) {
return "YES";
} else {
return "NO";
}
}
}
'코딩테스트' 카테고리의 다른 글
[힌트 문제2-5] 트리 (0) | 2023.09.27 |
---|---|
[힌트 문제1-4] 비트 연산자 (0) | 2023.09.20 |
[힌트 문제1-5] 개수 세기 (0) | 2023.09.19 |
[힌트 문제1-2]숫자 문자열과 영단어 (0) | 2023.09.19 |
[힌트 문제1-1]짝수는 싫어요 (0) | 2023.09.19 |