Skip to content

Commit e956ef6

Browse files
authored
Create numbers-with-same-consecutive-differences.py
1 parent ff49e5a commit e956ef6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Time: O(2^n)
2+
# Space: O(2^n)
3+
4+
class Solution(object):
5+
def numsSameConsecDiff(self, N, K):
6+
"""
7+
:type N: int
8+
:type K: int
9+
:rtype: List[int]
10+
"""
11+
curr = range(10)
12+
for i in xrange(N-1):
13+
curr = [x*10 + y for x in curr for y in set([x%10 + K, x%10 - K])
14+
if x and 0 <= y < 10]
15+
return curr

0 commit comments

Comments
 (0)