The last case [-1,2,0,-1,1,0,1] is not pass


  • 0
    S

    Why the last case [-1,2,0,-1,1,0,1] is wrong

    class Solution {
    public:
        void backtrace(vector<int>& nums, int order,  vector<vector<int>>& subs) {
            if (order == nums.size()) {
                subs.push_back(nums);
                return;
            }
            int temp = INT_MIN;
            for (int i = order; i < nums.size(); i++) {
                if (i != order && nums[i] == nums[order]) {
                    continue;
                }
                if (temp == nums[i]) {
                    continue;
                }
                temp = nums[i];
                swap(nums[order], nums[i]);
                backtrace(nums, order + 1, subs);
                swap(nums[order], nums[i]);
            }
        }
        
        vector<vector<int>> permuteUnique(vector<int>& nums) {
            vector<vector<int>> subs;
            sort(nums.begin(), nums.end());
            backtrace(nums, 0, subs);
            return subs;
        }
    };
    

Log in to reply
 

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