problem:
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
For example,
If n = 4 and k = 2, a solution is:
thinking:
(1)看到題就應想到用DFS深搜法
(2)深搜的難點在于下1步怎樣處理,這里開1個K大小的數組,記錄深搜的每步獲得的數字
(3)時間復雜度為O(K*N),空間復雜度為O(k)
code:
上一篇 23種設計模式匯總整理
下一篇 求解最大公約數和最小公倍數問題