-
[LeetCode] 77. Combinations알고리즘 2022. 4. 28. 23:39
77. Combinations
풀이_#1
재귀를 돌려서 풀었슴!
import copy class Solution: def combine(self, n: int, k: int) -> List[List[int]]: r = [] visited = [0] * (n + 1) def rec(l): if (len(l) == k): r.append(copy.deepcopy(l)) return ; nowNum = l[-1] for i in range(nowNum + 1, n+1): l.append(i) rec(l) l.remove(i) for i in range(1, n + 2 - k): l = [i] rec(l) l.remove(i) return r'알고리즘' 카테고리의 다른 글
70. Climbing Stairs (0) 2022.04.30 [LeetCode] 46. Permutations (0) 2022.04.28 [LeetCode] 206. Reverse Linked List (0) 2022.04.28 [LeetCode] 21. Merge Two Sorted Lists (0) 2022.04.28 [LeetCode] 21. Merge Two Sorted Lists (0) 2022.04.28