반응형
leetcode.com/problems/valid-parentheses/submissions/
Solution
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
32
33
|
char stack[10000];
int cnt = 0;
void push(char c){
stack[cnt++] = c;
}
char pop(){
if(cnt==0) return '@';
return stack[--cnt];
}
bool isValid(char * s){
cnt = 0;
while(*s){
if(*s=='(' || *s=='[' || *s=='{'){
push(*s);
}else{
char c = pop();
if(c=='@') return false;
if(c=='(' && *s!=')') return false;
if(c=='[' && *s!=']') return false;
if(c=='{' && *s!='}') return false;
}
s++;
}
if(cnt>0) return false;
return true;
}
|
cs |
반응형
'코딩테스트 > Leetcode' 카테고리의 다른 글
Leetcode - [Medium]6. ZigZag Conversion (0) | 2021.03.25 |
---|---|
Leetcode - [Easy]14. Longest Common Prefix (0) | 2021.03.22 |
Leetcode - [Easy]13. Roman to Integer (0) | 2021.03.14 |
Leetcode - [Medium]3. Longest Substring Without Repeating Characters (0) | 2021.03.07 |
Leetcode - [Medium]2. Add Two Numbers (0) | 2021.03.04 |