C++ 7 lines nums[i]=-nums[i] solution


  • 0
    vector<int> findDisappearedNumbers(vector<int>& nums) {
            vector<int>res;
            for(int i=0;i<nums.size();i++){
                int val=abs(nums[i])-1;
                if(nums[val]>0) nums[val]=-nums[val];
            }
            for(int i=0;i<nums.size();i++) if(nums[i]>0) res.push_back(i+1);
            return res;
        }
    

Log in to reply
 

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