-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion20.java
More file actions
43 lines (42 loc) · 931 Bytes
/
question20.java
File metadata and controls
43 lines (42 loc) · 931 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
31
32
33
34
35
36
37
38
39
40
41
42
43
class Solution {
public boolean isValid(String s) {
int l=s.length();
int i;
char arr[]=new char[l];
char ch;
int fg=1;
int top=-1;
for(i=0;i<l;i++)
{
ch=s.charAt(i);
if(ch=='('||ch=='{'||ch=='[')
{
top++;
arr[top]=ch;
}
else
{
if(top!=-1)
{
if((ch=='}'&&arr[top]=='{')||(ch==']'&&arr[top]=='[')||(ch==')'&&arr[top]=='('))
{
top--;
}
else
{
fg=0;
break;
}
}
else
{
fg=0;
break;
}
}
}
if(top==-1&&fg==1)
return true;
return false;
}
}