Simple Java Solution


  • 0
    D
    class Solution {
    public:
    vector<vector<int>> result;
    void recur(vector<int> temp, int k,int n, int start){
        if(k == temp.size()){
            result.push_back(temp);
            return;    
        }
        for(int i = start; i<n+1;i++){
            temp.push_back(i);
            recur(temp,k,n ,i+1);
            temp.pop_back();
        }
    }
    vector<vector<int>> combine(int n, int k) {
        vector<int> temp;
        for(int i = 1; i<n+1; i++){
            temp.push_back(i);
            recur(temp, k, n,i+1);
            temp.pop_back();
        }
        return result;
    }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.