-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsolution.py
More file actions
18 lines (17 loc) · 619 Bytes
/
Copy pathsolution.py
File metadata and controls
18 lines (17 loc) · 619 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution:
# Time: O(2^n)
# Space: O(2^n)
def find_strobogrammatic(self, n: int) -> list[str]:
def build(length: int) -> list[str]:
if length == 0:
return [""]
if length == 1:
return ["0", "1", "8"]
results: list[str] = []
for middle in build(length - 2):
for left, right in ("11", "88", "69", "96"):
results.append(left + middle + right)
if length != n:
results.append("0" + middle + "0")
return results
return build(n)