Skip to content

Commit 93bb327

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 877fcd3 commit 93bb327

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

backtracking/generate_parentheses_iterative.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def generate_parentheses_iterative(length: int) -> list[str]:
1818
1919
Returns:
2020
A list of strings representing valid combinations of parentheses
21-
21+
2222
Raises:
2323
ValueError: If length is negative
2424
TypeError: If length is not an integer
@@ -29,7 +29,7 @@ def generate_parentheses_iterative(length: int) -> list[str]:
2929
Space Complexity:
3030
O(4^n / sqrt(n)) - Storage for all valid combinations
3131
32-
32+
3333
>>> generate_parentheses_iterative(3)
3434
['()()()', '()(())', '(())()', '(()())', '((()))']
3535
>>> generate_parentheses_iterative(2)
@@ -52,13 +52,13 @@ def generate_parentheses_iterative(length: int) -> list[str]:
5252
raise TypeError("length must be an integer")
5353
if length < 0:
5454
raise ValueError("length must be non-negative")
55-
55+
5656
# Handle edge case
5757
if length == 0:
5858
return [""]
59-
59+
6060
result: list[str] = []
61-
61+
6262
# Each element in stack is a tuple (current_combination, open_count, close_count)
6363
stack: list[tuple[str, int, int]] = [("", 0, 0)]
6464

@@ -69,11 +69,11 @@ def generate_parentheses_iterative(length: int) -> list[str]:
6969
if len(current_combination) == 2 * length:
7070
result.append(current_combination)
7171
continue
72-
72+
7373
# Add '(' if we haven't used all open parentheses
7474
if open_count < length:
7575
stack.append((current_combination + "(", open_count + 1, close_count))
76-
76+
7777
# Add ')' if it maintains validity
7878
if close_count < open_count:
7979
stack.append((current_combination + ")", open_count, close_count + 1))

0 commit comments

Comments
 (0)