Skip to content

Commit b24e68d

Browse files
20. Valid Parentheses (#196)
* Create 20.ValidParentheses.py * Create 20.ValidParentheses.java * Delete 20.ValidParentheses.py * Update 20.ValidParentheses.java * Update README.md
1 parent 6939e9e commit b24e68d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Java/20.ValidParentheses.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//Time Complexity n
2+
//Space Complexity n
3+
public boolean isValid(String s) {
4+
Stack<Character> stack = new Stack<Character>();
5+
for (char c : s.toCharArray()) {
6+
if (c == '(')
7+
stack.push(')');
8+
else if (c == '{')
9+
stack.push('}');
10+
else if (c == '[')
11+
stack.push(']');
12+
else if (stack.isEmpty() || stack.pop() != c)
13+
return false;
14+
}
15+
return stack.isEmpty();
16+
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
203203

204204
| # | Title | Solution | Time | Space | Difficulty | Tag | Note |
205205
| ---- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | ------ | ------ | ---------- | ---------------------- | ---- |
206-
| 020 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [Python](./Python/20_ValidParentheses.py) [C++](./C++/Vlalid_Parentheses.cpp) | _O(n)_ | _O(n)_ | Easy | Stack | |
206+
| 020 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [Python](./Python/20_ValidParentheses.py) [C++](./C++/Vlalid_Parentheses.cpp)[Java](./Java/20.ValidParentheses.java) | _O(n)_ | _O(n)_ | Easy | Stack | |
207207
| 084 | [Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/) | [C++](./C++/Largest-Rectangle-in-Histogram.cpp) | _O(n)_ | _O(n)_ | Hard | Stack |
208208
| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./Python/150.EvaluateReversePolishNotation.py) <br> [Java](./Java/evaluate_reverse_polish_notation.java) | _O(n)_ | _O(1)_ | Medium | Stack | |
209209
| 1047 | [Remove All Adjacent Duplicates In String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/) | [C++](./C++/remove-all-adjacent-duplicates-in-string.cpp) | _O(n)_ | _O(n)_ | Easy | Stack | |

0 commit comments

Comments
 (0)