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 12b360e commit 3293b00Copy full SHA for 3293b00
leetcode/java/linkedlist/ValidParenthesis
@@ -0,0 +1,26 @@
1
+class Solution {
2
+ public boolean isValid(String s) {
3
+ if(s.length()%2!=0)
4
+ return false;
5
+ Stack <Character> stk=new Stack<Character>();
6
+ for(char c:s.toCharArray()){
7
+ if(c=='('||c=='{'||c=='['){
8
+ stk.push(c);}
9
+
10
+ else if(c==')'&&!stk.isEmpty()&&stk.peek()=='(')
11
+ stk.pop();
12
13
+ else if(c==']'&&!stk.isEmpty()&&stk.peek()=='[')
14
15
16
+ else if(c=='}'&&!stk.isEmpty()&&stk.peek()=='{')
17
18
+ else
19
20
21
22
23
+ }
24
+ return (stk.isEmpty());
25
26
+}
0 commit comments