-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.c
More file actions
30 lines (28 loc) · 649 Bytes
/
Copy path2.c
File metadata and controls
30 lines (28 loc) · 649 Bytes
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
#include <stdio.h>
#include <string.h>
int isValid(char * s){
char temp[256] = "";
char OPENER[] = "({[";
char CLOSER[] = ")}]";
for(int i = 0; i < strlen(s); i++){
if(strchr(OPENER,s[i])){
strncat(temp,&CLOSER[3-strlen(strchr(OPENER,s[i]))],1);
}else if(strlen(temp)>0){
if(temp[strlen(temp)-1] == s[i]){
temp[strlen(temp)-1] = '\0';
}else{
return 0;
}
}else{
return 0;
}
}
if(strlen(temp)!=0){
return 0;
}
return 1;
}
int main(){
char s[] = "()";
printf("%d",isValid(s));
}