LeetCode Array Easy 448. Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
Find all the elements of [1, n] inclusive that do not appear in this array.
Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.
Example:
Input:
[,,,,,,,] Output:
[,]
问题描述:给定一个数组,1 ≤ a[i] ≤ n (n为数据的长度) 数组中有的元素出现一次,有的出现两次,找到数组中没有出现的元素
思路:先遍历一遍做标记,然后再遍历一次,找到没有出现的元素
public IList<int> FindDisappearedNumbers(int[] nums) {
        //Array.Sort(nums);
        IList<int> res = new List<int>();
        for(int i = ; i < nums.Length; i++){
            int index = Math.Abs(nums[i])-;
            if(nums[index] > ){
                nums[index] = - * nums[index];
            }
        }
        for(int i = ; i < nums.Length; i++){
            if(nums[i] > ){
                res.Add(i+);
            }
        }
        return res;
    }

LeetCode Array Easy 448. Find All Numbers Disappeared in an Array的更多相关文章
- [LeetCode&Python] Problem 448. Find All Numbers Disappeared in an Array
		
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...
 - 448. Find All Numbers Disappeared in an Array【easy】
		
448. Find All Numbers Disappeared in an Array[easy] Given an array of integers where 1 ≤ a[i] ≤ n (n ...
 - 【leetcode】448. Find All Numbers Disappeared in an Array
		
problem 448. Find All Numbers Disappeared in an Array solution: class Solution { public: vector<i ...
 - leetcode 217. Contains Duplicate 287. Find the Duplicate Number 442. Find All Duplicates in an Array 448. Find All Numbers Disappeared in an Array
		
后面3个题都是限制在1-n的,所有可以不先排序,可以利用巧方法做.最后两个题几乎一模一样. 217. Contains Duplicate class Solution { public: bool ...
 - 448. Find All Numbers Disappeared in an Array&&645. Set Mismatch
		
题目: 448. Find All Numbers Disappeared in an Array Given an array of integers where 1 ≤ a[i] ≤ n (n = ...
 - 448. Find All Numbers Disappeared in an Array@python
		
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...
 - leetcode 448. Find All Numbers Disappeared in an Array -easy (重要)
		
题目链接: https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/description/ 题目描述: Give ...
 - LeetCode 448. Find All Numbers Disappeared in an Array (在数组中找到没有出现的数字)
		
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...
 - LeetCode: 448 Find All Numbers Disappeared in an Array(easy)
		
题目: Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice an ...
 
随机推荐
- Kconfig的简单例子
			
https://cloud.tencent.com/developer/article/1431908 使用Kconfig时,需要注意的地方 1.在Kconfig中定义的配置宏,前缀都没有" ...
 - SpringBoot---事务支持
			
1.自动配置的事务管理器 1.1.使用JDBC 作为 数据访问技术 时,SpringBoot 为我们 定义了 PlatformTransactionManager的实现 DataSourc ...
 - React笔记01——React开发环境准备
			
1 React简介 2013年由Facebook推出,代码开源,函数式编程.目前使用人数最多的前端框架.健全的文档与完善的社区. 官网:reactjs.org 阅读文档:官网中的Docs React ...
 - 4,fail-fast错误机制
			
一,fail-fast简介 在JDK的Collection中我们时常会看到类似于这样的话: ArrayList 注意,迭代器的快速失败行为无法得到保证,因为一般来说,不可能对是否出现不同步并发修改做出 ...
 - [CF1166C]A Tale of Two Lands题解
			
比赛的时候lowerbound用错了 现场WA on test4(好吧我承认我那份代码确实有除了lowerbound以外的问题) 于是只能手动二分 (我好菜啊QAQ 经过一波数学推算,我们发现,设序列 ...
 - Trailing Zeroes (III) -;lightoj  1138
			
Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...
 - WINDOWS2008server安全策略设置
			
一.防止黑客或恶意程序暴力破解我的系统密码 答: 暴力破解Windows密码实质上是通过穷举算法来实现,尤其是密码过于简单的系统,暴力破解的方法还是比较实用的.有一点需要我们注意,这个问题的关键在于W ...
 - CSS动画之旋转魔方轮播
			
很久没有回头来复习CSS方面的知识了, 正好又到了月底写文章的deadline......所以这次选择了详细巩固一下CSS3动画有关的知识点,因为之前只是用过一些属性并没有深究细节. 在我自己写完这篇 ...
 - UML 类图快速入门
			
UML 图形 官方定义 UML 类图(Class Diagram) UML 时序图(Sequence Diagram) 领域 UML 类图和实现 UML 类图 领域 UML 类图 实现 UML 类图 ...
 - 不同vlan之间相互通信
			
不同VLAN之间相互通信的两种方式 (单臂路由.三层交换) 试验目的: 1.通过单臂路由实现不同VLAN之间的通信 2.通过三层交换路由功能实现不同VLAN之间的通信 网络拓扑图: 1.单臂路由实 ...