Created
November 21, 2014 06:48
-
-
Save rohith2506/c6ebde3ab6ac1c9fee51 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
http://www.mytechinterviews.com/permutations-of-a-string | |
*/ | |
class Solution { | |
public: | |
void permutate(vector<int> arr, int index, vector<vector<int> > &result ) { | |
if(index == arr.size()) { | |
result.push_back(arr); | |
return ; | |
} | |
permutate(arr,index+1,result); | |
int last = arr[index]; | |
for(int i = index+1; i < arr.size(); i++) { | |
if(last == arr[i]) | |
continue; | |
else | |
last = arr[i]; | |
swap(arr[index],arr[i]); | |
permutate(arr,index+1,result); | |
swap(arr[index],arr[i]); | |
} | |
} | |
vector<vector<int> > permuteUnique(vector<int> &num) { | |
vector<vector<int> > result; | |
permutate(num,0,result); | |
return result; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment