forked from TheAlgorithms/C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20.c
29 lines (28 loc) · 730 Bytes
/
20.c
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
bool isValid(char * s){
int i, k = 0, len = strlen(s);
char *store = calloc(len, sizeof(char));
for( i = 0; s[i] != '\0'; i++) {
switch(s[i]) {
case '(':
case '{':
case '[':
store[k++] = s[i];
break;
case ')':
if(k < 1 || store[--k] != '(')
goto out;
break;
case '}':
if(k < 1 || store[--k] != '{')
goto out;
break;
case ']':
if(k < 1 || store[--k] != '[')
goto out;
break;
}
}
out:
free(store);
return s[i] == '\0' && k == 0;
}