File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -13,24 +13,23 @@ function isValid(s: string): boolean {
13
13
if ( s . length % 2 !== 0 ) return false ;
14
14
if ( s === '' ) return true ;
15
15
16
- const openingBrackets = [ '(' , '{' , '[' ] ;
17
16
const bracketSets : Record < string , string > = { '(' : ')' , '{' : '}' , '[' : ']' } ;
18
17
const bracketStack : string [ ] = [ ] ;
19
18
20
19
for ( const char of s ) {
21
- // 여는 경우, 스택에 추가
22
- if ( openingBrackets . includes ( char ) ) {
20
+ if ( char in bracketSets ) {
21
+ // 여는 괄호인 경우 스택에 추가
23
22
bracketStack . push ( char ) ;
24
23
} else {
25
- // 닫는 괄호 경우, 스택에서 가장 마지막에 추가한 여는 괄호를 꺼냄
24
+ // 닫는 괄호인 경우 스택에서 마지막 여는 괄호를 꺼냄
26
25
const lastOpeningBracket = bracketStack . pop ( ) ;
27
- // bracketSets 과 유효하지 않은 괄호인 경우
26
+ // 유효하지 않은 괄호 조합인 경우
28
27
if ( bracketSets [ lastOpeningBracket ! ] !== char ) {
29
28
return false ;
30
29
}
31
30
}
32
31
}
33
32
34
- // 스택이 비어있으면 모든 괄호가 유효한 경우
33
+ // 스택이 비어있으면 모든 괄호가 유효
35
34
return bracketStack . length === 0 ;
36
35
}
You can’t perform that action at this time.
0 commit comments