File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -203,7 +203,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
203
203
204
204
| # | Title | Solution | Time | Space | Difficulty | Tag | Note |
205
205
| ---- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | ------ | ------ | ---------- | ---------------------- | ---- |
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 | |
207
207
| 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 |
208
208
| 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 | |
209
209
| 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 | |
You can’t perform that action at this time.
0 commit comments