未验证 提交 69050b88 编写于 作者: K Keqi Huang 提交者: GitHub

Update 0247._Strobogrammatic_Number_II.md

上级 6e803eb4
......@@ -45,12 +45,7 @@ Output: ["11","69","88","96"]
```python
class Solution:
def findStrobogrammatic(self, n):
"""
:type n: int
:rtype: List[str]
"""
def findStrobogrammatic(self, n: int) -> List[str]:
def helper(n):
if n == 0:
return ['']
......@@ -66,11 +61,11 @@ class Solution:
res.append('9' + s + '6')
return res
if n == 0:
return ['']
if n == 1:
return ['0', '1', '8']
return [s for s in helper(n) if s[0] != '0']
res = []
for s in helper(n):
if not (len(s) > 1 and s[0] == '0'):
res.append(s)
return res
```
> 思路 2
......@@ -80,26 +75,23 @@ class Solution:
```python
class Solution:
def findStrobogrammatic(self, n):
"""
:type n: int
:rtype: List[str]
"""
res = [''] if n % 2 == 0 else ['0', '1', '8']
def findStrobogrammatic(self, n: int) -> List[str]:
stack = [''] if n % 2 == 0 else ['0', '1', '8']
for i in range(n%2+1, n, 2):
cur = []
for s in res:
for s in stack:
cur.append('0' + s + '0')
cur.append('1' + s + '1')
cur.append('6' + s + '9')
cur.append('8' + s + '8')
cur.append('9' + s + '6')
res = cur[:]
if n == 0:
return ['']
if n == 1:
return ['0', '1', '8']
return [s for s in res if s[0] != '0']
stack = cur[:]
res = []
for s in stack:
if not (len(s) > 1 and s[0] == '0'):
res.append(s)
return res
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册