mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 09:21:13 +08:00
Pyupgrade to Python 3.9 (#4718)
* Pyupgrade to Python 3.9 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -3,16 +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
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
def generate_all_combinations(n: int, k: int) -> List[List[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: List[List[int]] = []
|
||||
result: list[list[int]] = []
|
||||
create_all_state(1, n, k, [], result)
|
||||
return result
|
||||
|
||||
@ -21,8 +21,8 @@ def create_all_state(
|
||||
increment: int,
|
||||
total_number: int,
|
||||
level: int,
|
||||
current_list: List[int],
|
||||
total_list: List[List[int]],
|
||||
current_list: list[int],
|
||||
total_list: list[list[int]],
|
||||
) -> None:
|
||||
if level == 0:
|
||||
total_list.append(current_list[:])
|
||||
@ -34,7 +34,7 @@ def create_all_state(
|
||||
current_list.pop()
|
||||
|
||||
|
||||
def print_all_state(total_list: List[List[int]]) -> None:
|
||||
def print_all_state(total_list: list[list[int]]) -> None:
|
||||
for i in total_list:
|
||||
print(*i)
|
||||
|
||||
|
Reference in New Issue
Block a user