LeetCode-448. Find All Numbers Disappeared in an Array C#
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:
[4,3,2,7,8,2,3,1] Output:
[5,6]
Solution:
Mark the value of already apeared index to negative, then loop it through to find the positive ones , then the index of positive ones is the result;
public class Solution {
public IList<int> FindDisappearedNumbers(int[] nums) {
int n = nums.Length;
IList<int> result = new List<int>();
for(int i=; i<n;i++)
{
int index = Math.Abs(nums[i]);
if(nums[index-]>)
{
nums[index-]=-nums[index-];
}
}
for(int i=; i<n;i++)
{
if(nums[i]>)
{
result.Add(i+);
}
}
return result;
}
}
LeetCode-448. Find All Numbers Disappeared in an Array C#的更多相关文章
- 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 (重要)
题目链接: https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/description/ 题目描述: Give ...
- LeetCode "448. Find All Numbers Disappeared in an Array"
My first reaction is to have an unlimited length of bit-array, to mark existence. But if no extra me ...
- 5. 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 解题报告
题目要求 Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice a ...
- 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 ...
- LeetCode 448. Find All Numbers Disappeared in an Array找到所有数组中消失的元素
题目 给定一个范围在 1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次. 找到所有在 [1, n] 范围之间没有出现在数组中的数字. 您能 ...
- [LeetCode] 448. Find All Numbers Disappeared in an Array 找到数组中消失的数字
题目描述 给定n个数字的数组,里面的值都是1-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 ...
随机推荐
- SSH整合之_架构的历史序列图
只用jsp最原始的架构 jsp+DB的2层架构 jsp+DB+_Entity的2层架构 jsp+DB+_Entity3_+Service的三层架构 jsp+DB+_Entity3_+Service_H ...
- xml数据解析
xml数据解析 在iPhone开发中,XML的解析有很多选择,iOS SDK提供了NSXMLParser和libxml2两个类库,另外还有很多第三方类库可选,例如TBXML.TouchXML.Kiss ...
- Linux内核网络协议栈优化总纲
本文原创为freas_1990 转载请标明出处:http://blog.csdn.net/freas_1990/article/details/9474121 Jack:淫龙,Linux内核协议栈如 ...
- 使用diff和patch指令生成文件差异和还原文件
使用diff和patch指令生成文件差异和还原文件 创建一个新的文件夹test然后进入test mkdir test cd test 首先创建文件a vim a.txt 随便输入一段文字后保存不退出. ...
- Android实现通过手机找回密码
其实这篇文章有点标题党,代码没有几行,真不好意思,但是确实给出了解决方案,这个我觉得还是很重要的,代码写了几年之后其实比较注重的就是思路跟方法了. 背景:手机客户端有这么一个需求,用户忘记密码了,然后 ...
- UIColor RGB颜色对照表
色 彩 RGB 值 对 照 表 color red green blue Hexadecimal triplet example Aliceblue 240 248 255 f0f8ff ...
- Maven 插件 maven-tomcat7-plugin - 常用命令及配置
常用命令 tomcat7:deploy 说明:部署 WAR 到 Tomcat tomcat7:help 说明:查看插件帮助信息 tomcat7:run 说明:支行当前项目 配置 <project ...
- Oracle 数据备份、恢复以及导入时表空间不存在的解决方案
一.数据备份(导出) 1.exp命令导出dmp文件(exp -help查看帮助信息) 命令:exp username/userpasswd@192.168.99.199/orcl file=C:\jd ...
- 【C#】【SHARE】The registering of global hotkeys
I remember that when I was still using VB6 sereval years ago, if global hotkeys are required, a mass ...
- ORA-01940无法删除当前已连接用户
原文地址:ORA-01940无法删除当前已连接用户作者:1736188794 1)查看用户的连接状况 select username,sid,serial# from v$session ------ ...