Skip to content

Latest commit

 

History

History

77-Combinations

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Combinations

Problem can be found in here!

Solution: Backtracking

def combine(n: int, k: int) -> List[List[int]]:
    def helper(tempt: List[int], index: int):
        if len(tempt) == k:
            result.append(tempt[:])
            return

        for i in range(index, n+1):
            tempt.append(i)
            helper(tempt, i+1)
            tempt.pop()

    result = []
    helper([], 1)
    return result