classSolution(object): defdfs(self, n, k, path, rs): if len(path) == k: rs.append(path[:]) return for i in xrange(1, n + 1): ifnot path or path[-1] < i: path.append(i) self.dfs(n, k, path, rs) path.pop()
defcombine(self, n, k): """ :type n: int :type k: int :rtype: List[List[int]] """ path = [] rs = [] self.dfs(n, k, path, rs) return rs