Description
Given two integers n and k, return all possible combinations of k numbers out of 1 … n.
Example:
1 | Input: n = 4, k = 2 |
解法
典型的深度优先搜索题,采用递归写就好了,start标记从start开始向后做选择,当搜索完成helper返回后注意回溯。
具体代码如下:
1 | class Solution { |
Thinking outside the box
Given two integers n and k, return all possible combinations of k numbers out of 1 … n.
Example:
1 | Input: n = 4, k = 2 |
典型的深度优先搜索题,采用递归写就好了,start标记从start开始向后做选择,当搜索完成helper返回后注意回溯。
具体代码如下:
1 | class Solution { |