-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path77.py
More file actions
29 lines (26 loc) · 700 Bytes
/
77.py
File metadata and controls
29 lines (26 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution(object):
def combine(self, n, k):
"""
:type n: int
:type k: int
:rtype: List[List[int]]
"""
ret = []
self.recursive(range(1, n+1), k, [], ret)
return ret
def recursive(self, l, k, nums, ret):
if len(nums)==k:
# print ret
# nums.sort()
# print nums
ret.append(nums+[])
nums = []
return
for i in range(len(l)):
# print nums
nums.append(l[i])
self.recursive(l[i+1:], k, nums, ret)
nums.pop()
if __name__ == '__main__':
solution = Solution()
print solution.combine(4, 2)