* Fix mypy in #2684

* fix pre-commit
This commit is contained in:
John Law
2020-11-30 01:30:31 +08:00
committed by GitHub
parent 0febbd397e
commit 25164bb638
5 changed files with 34 additions and 22 deletions

View File

@ -3,15 +3,16 @@
numbers out of 1 ... n. We use backtracking to solve this problem.
Time complexity: O(C(n,k)) which is O(n choose k) = O((n!/(k! * (n - k)!)))
"""
from typing import List
def generate_all_combinations(n: int, k: int) -> [[int]]:
def generate_all_combinations(n: int, k: int) -> List[List[int]]:
"""
>>> generate_all_combinations(n=4, k=2)
[[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
"""
result = []
result: List[List[int]] = []
create_all_state(1, n, k, [], result)
return result
@ -20,8 +21,8 @@ def create_all_state(
increment: int,
total_number: int,
level: int,
current_list: [int],
total_list: [int],
current_list: List[int],
total_list: List[List[int]],
) -> None:
if level == 0:
total_list.append(current_list[:])
@ -33,7 +34,7 @@ def create_all_state(
current_list.pop()
def print_all_state(total_list: [int]) -> None:
def print_all_state(total_list: List[List[int]]) -> None:
for i in total_list:
print(*i)