class Solution { public: vector<vector<int>> res; void dfs(vector<int> &num,vector<int> list,int visited[]){ if(num.size() == list.size()){ res.push_back(list); return ; } for(int i = 0; i < num.size(); i++){ if(visited[i] || i > 0 && num[i-1] == num[i] && !visited[i-1])// 如果访问过、或者 前后相邻两个元素一样且前面的元素visited标志为false【实则同一个位置相同的元素已经访问过】 continue; visited[i] = true; list.push_back(num[i]); dfs(num,list,visited); visited[i] = false; list.pop_back(); } } vector<vector<int>> permuteUnique(vector<int> &num) { sort(num.begin(),num.end()); int visited[8] = {0}; vector<int> list; dfs(num,list,visited); return res; } };