Skip to content

Commit cd0919d

Browse files
add problem 77
1 parent 29d9be9 commit cd0919d

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Python/sln_1_100/solution_71_80.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# -*- coding: utf-8 -*-
2+
from typing import List
3+
import copy
4+
import math
5+
6+
27
class Solution_71_80(object):
38
def simplifyPath(self, path):
49
"""
@@ -31,3 +36,27 @@ def simplifyPath(self, path):
3136
final_path_segments.append(segment)
3237

3338
return '/' + '/'.join(final_path_segments)
39+
40+
def combine(self, n: int, k: int) -> List[List[int]]:
41+
"""
42+
77
43+
:param n:
44+
:param k:
45+
:return:
46+
"""
47+
48+
results = []
49+
50+
def backtrace(res=[]):
51+
if len(res) == k:
52+
results.append(res)
53+
else:
54+
if not res:
55+
m = 1
56+
else:
57+
m = res[-1] + 1
58+
for i in range(m, n + 1):
59+
backtrace(res + [i])
60+
61+
backtrace()
62+
return results

Python/sln_1_100/test_solution_71_80.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest import TestCase
33
from sln_1_100.solution_71_80 import Solution_71_80
44

5+
56
class TestSolution_71_80(TestCase):
67
def setUp(self):
78
self.sln = Solution_71_80()
@@ -11,5 +12,9 @@ def test_simplifyPath(self):
1112
print(ret)
1213
ret2 = self.sln.simplifyPath('/a/./b///../c/../././../d/..//../e/./f/./g/././//.//h///././/..///')
1314
print(ret2)
14-
self.assertEqual(self.sln.simplifyPath('///'),'/')
15+
self.assertEqual(self.sln.simplifyPath('///'), '/')
1516
self.assertEqual(self.sln.simplifyPath('/...'), '/...')
17+
18+
def test_combine(self):
19+
ret = self.sln.combine(4, 2)
20+
self.assertEqual(ret, [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]])

0 commit comments

Comments
 (0)