We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 297d171 commit b002fbeCopy full SHA for b002fbe
0020VALIDPARENTHESIS.java
@@ -0,0 +1,51 @@
1
+class Solution {
2
+ public boolean isValid(String s) {
3
+ Stack<Character> st = new Stack<>();
4
+
5
+ for(int i= 0 ; i<s.length();i++){
6
+ char ch= s.charAt(i);
7
8
+ if (ch=='('|| ch=='[' || ch=='{'){
9
+ st.push(ch);
10
11
+ }
12
+ else{
13
+ if(st.isEmpty()){
14
+ return false;
15
16
17
+ else if(ch==']' && st.peek()!='['){
18
19
20
21
22
+ else if(ch=='}' && st.peek()!='{'){
23
24
25
26
+ else if(ch==')' && st.peek()!='('){
27
28
29
30
31
32
33
+ st.pop();
34
35
36
37
38
39
40
+ return true;
41
42
43
+ else {
44
45
46
47
48
49
50
+}
51
0 commit comments