-
Notifications
You must be signed in to change notification settings - Fork 0
/
No_20.ts
34 lines (33 loc) · 1.05 KB
/
No_20.ts
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
34
namespace Leetcode{
export class No_20 {
isValid(s: string): boolean {
let stack = [], i = 0;
while (i < s.length) {
if (s[i] == '{' || s[i] == '[' || s[i] == '(')
stack.push(s[i]);
else {
let op = stack.pop();
switch (op) {
case '(':
if (s[i] != ')')
return false;
break;
case '[':
if (s[i] != ']')
return false;
break;
case '{':
if (s[i] != '}')
return false;
break;
default:
return false;
break;
}
}
i++;
}
return !(stack.length > 0);
};
}
}