Leetcode - Strings | Valid Parentheses
20. Valid Parentheses[E]
https://leetcode.com/problems/valid-parentheses/
Description
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
- Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
Note that an empty string is also considered valid.
Example 1:
1 | Input: "()" |
Example 2:
1 | Input: "()[]{}" |
Example 3:
1 | Input: "(]" |
Example 4:
1 | Input: "([)]" |
Example 5:
1 | Input: "{[]}" |
Solution
1 | class Solution: |
https://leetcode.com/problems/valid-parentheses/solution/
1 | def isValid(self, s): |
32. Longest Valid Parentheses[H]
https://leetcode.com/problems/longest-valid-parentheses/
Description
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
Example 1:
1 | Input: "(()" |
Example 2:
1 | Input: ")()())" |
Solution
https://leetcode.com/problems/longest-valid-parentheses/solution/
1 | class Solution: |
301. Remove Invalid Parentheses[H]
https://leetcode.com/problems/remove-invalid-parentheses/
Description
Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.
Note: The input string may contain letters other than the parentheses ( and ).
Example 1:
1 | Input: "()())()" |
Example 2:
1 | Input: "(a)())()" |
Example 3:
1 | Input: ")(" |
Solution
https://leetcode.com/problems/remove-invalid-parentheses/solution/
https://leetcode.com/problems/remove-invalid-parentheses/discuss/75028/Short-Python-BFS
1 |
22. Generate Parentheses
https://leetcode.com/problems/generate-parentheses/
Description
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
For example, given n = 3, a solution set is:
1 | [ |
Solution
https://leetcode.com/problems/generate-parentheses/solution/
1 | class Solution: |





