DSA/Algorithm
[LeetCode 77] Combinations
돌래씨
2022. 10. 4. 02:47
반응형
https://leetcode.com/problems/combinations/
Combinations - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
Think
이번에도 영상을 보자..~
https://www.youtube.com/watch?v=q0s6m7AiM7o
Solution
1. 파이썬 답게,, 라이브러리를 사용하는 풀이
class Solution(object):
def combine(self, n, k):
"""
:type n: int
:type k: int
:rtype: List[List[int]]
"""
# 단 한 줄로 풀린다
return list(itertools.combinations(range(1, n+1), k))
2. dfs를 직접 구현하는 풀이
-> 이것도 나중에 꼭 해보자!!
Get
조합 문제는 itertools.combinations() 사용!
반응형