Why use regular backtracking solutions with Vector does not work .The result contains some duplicate values inside the vector


  • 0
    T

    class Solution {
    public:
    vector<vector<int>> permute(vector<int>& num) {
    vector<vector<int>> vv;
    vector<int> v;
    helper(0, num, v, vv);
    return vv;
    }
    void helper(int start, vector<int>& num, vector<int>& v, vector<vector<int>>& vv) {
    if (start >= num.size()) {
    vv.push_back(v);
    return;
    }
    for (int i=start; i<num.size(); i++) {
    v.push_back(num[i]);
    helper(start+1, num, v, vv);
    v.pop_back();
    }
    }
    };


Log in to reply
 

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