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 bf065f7 commit 1873ea2Copy full SHA for 1873ea2
Solutions/0020_Valid Parantheses.java
@@ -0,0 +1,23 @@
1
+class Solution {
2
+ public boolean isValid(String s)
3
+ {
4
+ Stack<Character> stack = new Stack<>();
5
+ for(char c : s.toCharArray())
6
7
+ if(c == '{' || c == '[' || c == '(') stack.push(c);
8
+ else
9
10
+ if(stack.isEmpty()) return false;
11
12
13
+ char top = stack.peek();
14
+ if(c == '}' && top == '{' ||
15
+ c == ')' && top =='(' ||
16
+ c == ']' && top == '[') stack.pop();
17
+ else return false;
18
+ }
19
20
21
+ return stack.isEmpty();
22
23
+}
0 commit comments