zoukankan      html  css  js  c++  java
  • Leetcode448.Find All Numbers Disappeared in an Array找到所有数组中消失的数字

    给定一个范围在  1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次。

    找到所有在 [1, n] 范围之间没有出现在数组中的数字。

    您能在不使用额外空间且时间复杂度为O(n)的情况下完成这个任务吗? 你可以假定返回的数组不算在额外空间内。

    示例:

    输入: [4,3,2,7,8,2,3,1] 输出: [5,6]

    class Solution {
    public:
    	vector<int> findDisappearedNumbers(vector<int>& nums) {
    		int len = nums.size();
    		map<int, int> check;
    		vector<int> res;
    		for (int i = 0; i < len; i++)
    		{
    			check[nums[i]]++;
    		}
    		for (int i = 1; i <= len; i++)
    		{
    			if (check[i] == 0)
    				res.push_back(i);
    		}
    		return res;
    	}
    };
  • 相关阅读:
    pod间访问
    Android地图下钻(坑我好久)
    学习进度23
    学习进度22
    人月神话读后感03
    团队介绍
    人月神话读后感02
    学习进度21
    学习进度20
    学习进度19
  • 原文地址:https://www.cnblogs.com/lMonster81/p/10434089.html
Copyright © 2011-2022 走看看