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 3e7337b commit 5e55437Copy full SHA for 5e55437
Easy/Valid Parantheses.java
Easy/Valid Parentheses.java
@@ -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