We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents e221c2d + d93b995 commit 2be06aeCopy full SHA for 2be06ae
java/Valid Parentheses.java
@@ -0,0 +1,47 @@
1
+class Solution {
2
+ public boolean isValid(String s) {
3
+
4
+ ArrayDeque<Character> dq = new ArrayDeque<Character>(s.length());
5
6
+ boolean valid = false;
7
8
+ int i;
9
+ for(i=0;i<s.length();i++){
10
+ char c = s.charAt(i);
11
12
+ if(c=='(' || c=='{' || c=='['){
13
+ dq.add(c);
14
+ }
15
16
+ if(dq.isEmpty()){
17
+ return true;
18
19
20
+ if(c=='}' && dq.getLast() != '{'){
21
+ return false;
22
23
+ else{
24
+ dq.removeLast();
25
26
27
+ if(c==')' && dq.getLast() != '('){
28
29
30
31
32
33
34
+ if(c==']' && dq.getLast() != '['){
35
36
37
38
39
40
41
42
43
44
45
+ return (true);
46
47
+}
0 commit comments