Last active
August 29, 2015 14:06
-
-
Save walkingtospace/eb503051e0861e18af6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://oj.leetcode.com/problems/permutations/ | |
class Solution { | |
public: | |
vector<vector<int>> permute(vector<int> &num) { | |
vector<vector<int>> res; | |
if(num.size() == 0) { | |
return res; | |
} | |
permute(0, num.size(), num, res); | |
return res; | |
} | |
void permute(int i, int n, vector<int>& num, vector<vector<int>>& res) { | |
if(i >= n-1) { | |
res.push_back(num); | |
return; | |
} | |
for(int k=i; k<num.size() ; ++k) { | |
swap(num[i],num[k]); | |
permute(i+1,n,num,res); | |
swap(num[i], num[k]); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment