[LeetCode] Combinations

yoonene·2023년 2월 1일
0

알고리즘

목록 보기
43/62

문제 이동
난이도: ⭐️⭐️

첫 번째 제출

class Solution:
    def combine(self, n: int, k: int) -> List[List[int]]:
        def combination(index, res):
            if len(res) == k:
                results.append(res)
                return
            for i in range(index, n):
                combination(i+1, res + [i+1])

        results = []
        combination(0, [])
        return results

앞에 포스팅한 permutation과 크게 다르지 않지만
조합이라 index를 사용해서 앞 숫자는 사용하지 않게 하였다.

ez 근데 또 나중에 풀면 못 풀겠지ㅋ

profile
NLP Researcher / Information Retrieval / Search

0개의 댓글