Skip to content

Commit

Permalink
Update LeetCode Post " LeetCode : 20. Valid Parentheses "
Browse files Browse the repository at this point in the history
  • Loading branch information
goodGid committed Jun 2, 2024
1 parent 193d69d commit a1d8710
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions _posts/2020-12-16-LeetCode-Valid-Parentheses.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,39 @@ private static final Map<Character, Character> MAPS = new HashMap<Character, Cha
};
```

---

### [2] Code (24. 06. 02)

*Retry*

``` java
// Runtime: 2 ms
// Memory Usage: 37 MB
// Ref : https://leetcode.com/submissions/detail/431285981
class Solution {
public boolean isValid(String s) {
Map<Character, Character> map = Map.of(')', '(', '}', '{', ']', '[');
Stack<Character> stack = new Stack<>();

for (Character c : s.toCharArray()) {
if (c == '(' || c == '{' || c == '[') {
stack.push(c);
} else if (stack.isEmpty() || stack.pop() != map.get(c)) {
return false;
}
}

return stack.isEmpty();
}
}
```

> Review
* 스무스하게 풀었다.


---

## Reference
Expand Down

0 comments on commit a1d8710

Please sign in to comment.