1 class Solution 
 2 {
 3 public:
 4     vector<vector<int>> combine(int n, int k) 
 5     {
 6         vector<vector<int>> res;
 7         int i=0;
 8         vector<int> cur(k,0);
 9         while(i>=0)
10         {
11             cur[i]++;
12             if(cur[i]>n)
13                 i--;
14             else if(i==k-1)
15                 res.push_back(cur);
16             else
17             {
18                 i++;
19                 cur[i]=cur[i-1];
20             }
21         }
22         return res;
23     }
24 };

从前向后推,以升序序列为基准构成答案序列

posted on 2018-07-25 10:06  高数考了59  阅读(119)  评论(0)    收藏  举报