You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use a stack to ensure every opening bracket has a matching closing bracket in the correct order.
8
+
9
+
## Approach
10
+
Iterate through the string, pushing opening brackets onto a stack and popping to match each closing bracket; return false if a mismatch or leftover remains.
11
+
12
+
## Complexity
13
+
- Time: O(n)
14
+
- Space: O(n)
15
+
16
+
## Notes
17
+
- Handle cases where the string starts with a closing bracket or ends with unmatched openings.
18
+
- Use a helper function to map each closing bracket to its corresponding opening bracket.
19
+
- Works for all three bracket types: (), {}, [].
20
+
- Returns false immediately on any mismatch or if the stack is not empty at the end.
Copy file name to clipboardExpand all lines: problems/README.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,9 @@
3
3
| Number | Title | NeetCode 150 | Link | Folder |
4
4
| ------ | ----- | ------------ | ---- | ------ |
5
5
| 0001 | Two Sum | true |[Link](https://leetcode.com/problems/two-sum/)|[0001-two-sum](0001-two-sum)|
6
+
| 1 | Two Sum | false |[Link](https://leetcode.com/problems/two-sum/)|[1-two-sum](1-two-sum)|
6
7
| 0019 | Remove Nth Node From End Of List | true |[Link](https://leetcode.com/problems/remove-nth-node-from-end-of-list/)|[0019-remove-nth-node-from-end-of-list](0019-remove-nth-node-from-end-of-list)|
0 commit comments