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 ...
随机推荐
- openGL如何在改变窗口大小时,使自己的图形不被拉伸
这里要注意两个概念:视口和视景体,当视口的纵横比和视景体的纵横比相同的时候,改变窗口大小,图像才不会变形: 视景体是指成像景物所在空间的集合.它是一个空间集合体. 单个的视景体,比如一个球体,若要完全 ...
- git 日常 常用命令
初始化git git init 第一次拉代码: 方式1:git clone git clone https://git.oschina.net/*****.git (https远程仓库地址) 方式2: ...
- nginx 重写
rewrite指令可在 server 块或者 location 块中配置. 语法: rewrite regex replacement [flag]; 1.rewrite 接收的 uri 不包含 ho ...
- Centos 的防火墙(firewalld,iptables)
Centos系统防火墙介绍 概述: 1.Filewalld(动态防火墙)作为redhat7系统中变更对于netfilter内核模块的管理工具: 2.iptables service 管理防火墙规则的模 ...
- Git的配置与基本操作
Git是一个版本控制软件,它可以让我们能够拍摄处于可行状态的项目的快照,修改项目(如实现新功能)后,如果项目不能正常运行,可以恢复到前一个可行状态. 通过使用版本控制,我们可以无忧无虑的改进项目,不用 ...
- javascrip的数组扁平化
扁平化 数组的扁平化,就是将一个嵌套多层的数组 array (嵌套可以是任何层数)转换为只有一层的数组. 举个例子,假设有个名为 flatten 的函数可以做到数组扁平化,效果就会如下: var ar ...
- maven编译问题之 -The POM for XXX is invalid, transitive dependencies (if any) will not be available
问题一: 把父工程tao-parent install 到maven本地仓后,接着install tao-common工程,然后报错 报错信息如下: [WARNING] The POM for com ...
- 阿里云E-HPC联合安世亚太、联科集团共建云超算生态
5月23日,2018云栖大会武汉峰会,阿里云高级技术专家刘峥和张维,对弹性计算最新上线的 serverless (无服务器化)计算技术Bazaar及基于该技术的容器服务产品 Severless Kub ...
- luogu P1449 后缀表达式 x
题目描述 所谓后缀表达式是指这样的一个表达式:式中不再引用括号,运算符号放在两个运算对象之后,所有计算按运算符号出现的顺序,严格地由左而右新进行(不用考虑运算符的优先级). 如:3*(5–2)+7对应 ...
- hibernate插入数据测试无异常,但数据库没有数据
解决方法: spring test测试默认会将事务回滚,如果想阻止spring transactional回滚,在test方法上加注解@Rollback(false)即可. Hibernate hql ...