File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed
Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 11def generate_parentheses_iterative (length : int ) -> list :
22 """
33 Generate all valid combinations of parentheses (Iterative Approach).
4-
4+
55 The algorithm works as follows:
66 1. Initialize an empty list to store the combinations.
77 2. Initialize a stack to keep track of partial combinations.
@@ -12,16 +12,16 @@ def generate_parentheses_iterative(length: int) -> list:
1212 c. If open count is < length, push new combination with added '(' onto the stack.
1313 d. If close count < open count, push new combination with added ')' on stack.
1414 5. Return the result containing all valid combinations.
15-
15+
1616 Args:
1717 length: The desired length of the parentheses combinations
18-
18+
1919 Returns:
2020 A list of strings representing valid combinations of parentheses
21-
21+
2222 Time Complexity:
2323 O(2^(2n))
24-
24+
2525 Space Complexity:
2626 O(2^(2n))
2727
You can’t perform that action at this time.
0 commit comments