class Solution {
  public:
    vector<string> res;
    void dfs(vector<char> data, bool visited[], string list) {
        if (list.size() == data.size()){
            res.push_back(list);
            return;
        }
        for(int i = 0; i < data.size(); i++){
            if(visited[i] || i > 0 && data[i] == data[i-1] && !visited[i-1])
                continue;
            visited[i] = true;
            list += data[i];
            dfs(data,visited,list);
            list = list.substr(0,list.size()-1);
            visited[i] = false;
        }
    }   


    vector<string> Permutation(string str) {
        vector<char> data;
        for (int i = 0; i < str.size(); i++) {
            data.push_back(str[i]);
        }
        sort(data.begin(),data.end());
        bool visited[11] = {0};

        string list;
        dfs(data, visited, list);
        return res;
    }
};