4th LeetCode:22. Generate Parentheses
Solution1 Exceed Time Limit
We were demanded to create a system checking the parentheses is valid in a series of K pairs of parentheses.
The definition of “valid” is:
1. The amount of “(”s and “)”s must be equal.
2. The amount of “(” should be more than “)“ in the LHS of a “)”
3. No “)” in the left-most, and no “(” in the right-most.
The solution I gave was as follows:
- List all possible combinations of K “(”s and K “)”s excluding those “)” in the left-most or “(” in the right-most.
- Examine each combination:
a. Exclude repeated combinations
b. Exclude which has more “)”s than “(”s in LHS of any “)”
This solution was easy, but consume too much time, need to be revised