File tree Expand file tree Collapse file tree 2 files changed +19
-18
lines changed
Expand file tree Collapse file tree 2 files changed +19
-18
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 55.1 MB, 시간: 6.67 ms
7+ 메모리: 55 MB, 시간: 22.09 ms
88
99### 구분
1010
1616
1717### 제출 일자
1818
19- 2025년 08월 01일 12:00:57
19+ 2025년 09월 01일 19:08:56
2020
2121### 문제 설명
2222
Original file line number Diff line number Diff line change 1+ import java .util .*;
2+
13class Solution {
24 boolean solution (String s ) {
3- boolean answer = false ;
4- int count = 0 ;
5- for (int i = 0 ; i <s .length ();i ++){
6- if (s .charAt (i ) == '(' ){
7- count ++;
8- }
9- if (s .charAt (i ) == ')' ){
10- count --;
5+ Stack <Character > stack = new Stack <>();
6+
7+ String str = s .substring (1 ,s .length ());
8+ stack .push (s .charAt (0 ));
9+
10+ for (char ch : str .toCharArray ()){
11+ if (ch == ')' ){
12+ if (!stack .isEmpty () && stack .pop () == '(' ){
13+ continue ;
14+ }
15+ return false ;
1116 }
12- if (count < 0 ){
13- break ;
14- }
15- }
16- if (count == 0 ){
17- answer = true ;
17+ stack .push (ch );
1818 }
19+
1920
20- return answer ;
21+ return stack . isEmpty () ? true : false ;
2122 }
22- }
23+ }
You can’t perform that action at this time.
0 commit comments