C++Find All Numbers Disappeared in an Array - 132 ms


  • 0
    G
    class Solution {
    public:
        vector<int> findDisappearedNumbers(vector<int>& nums) 
        {
            int *allNums = new int[nums.size()];
    	for (int i = 0; i < nums.size(); i++)
    	  allNums[i] = 1;
    	for (vector<int>::iterator it = nums.begin(); it != nums.end(); it++)
    	  allNums[(*it)-1] = 0;
    	vector<int> res;
    	for (int i = 0; i < nums.size(); i++)
    	{
    	  if (allNums[i] == 1) 
    	    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.