A eazy C++ solution O(n)


  • 1
    D
    	vector<int> temp;
    	int *array = new int[nums.size()];
    	for (size_t i = 0; i < nums.size(); i++)
    	{
    		array[i] = 0;
    	}
    	for (size_t i = 0; i < nums.size(); i++)
    	{
    		array[nums[i]-1]++;
    	}
    	for (size_t i = 0; i < nums.size(); i++)
    	{
    		if (array[i] == 0)
    		{
    			temp.push_back(i + 1);
    		}
    	}
    	return temp;

Log in to reply
 

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