Skip to content

Commit 5e55437

Browse files
authored
Update and rename Valid Parantheses.java to Valid Parentheses.java
1 parent 3e7337b commit 5e55437

File tree

2 files changed

+17
-26
lines changed

2 files changed

+17
-26
lines changed

Easy/Valid Parantheses.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

Easy/Valid Parentheses.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public boolean isValid(String s) {
3+
String starting = "({[";
4+
String ending = ")}]";
5+
Stack<Character> stack = new Stack<>();
6+
for (char c : s.toCharArray()) {
7+
if (starting.indexOf(c) != -1) {
8+
stack.push(c);
9+
} else {
10+
if (stack.isEmpty() || starting.indexOf(stack.pop()) != ending.indexOf(c)) {
11+
return false;
12+
}
13+
}
14+
}
15+
return stack.isEmpty();
16+
}
17+
}

0 commit comments

Comments
 (0)