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;
}
}

最新文章

  1. iOS - 捕获应用程序崩溃日志
  2. 做的一个HTML表白页面
  3. x01.Weiqi.9: 点目功能
  4. Android 开发之旅:view的几种布局方式及实践
  5. NK3C开发要点
  6. Spring自定义一个拦截器类SomeInterceptor,实现HandlerInterceptor接口及其方法的实例
  7. U盘安装CentOS无法进入Centos系统解决办法
  8. python异常以及面向对象编程
  9. HDU-1846 Brave Game
  10. ReportViewer导出功能筛选
  11. Dede推荐文章与热点文章不显示?
  12. Linux负载均衡软件LVS之二(安装篇)
  13. 我总结的常用sql语句
  14. vagrant扩容
  15. python如何转换word格式、读取word内容、转成html
  16. 关于oracle设置主键自增的问题
  17. 6L - 大菲波数
  18. VsCode编写和调试.NET Core
  19. java线程池实例
  20. java iterator

热门文章

  1. 最小堆实现优先队列:Python实现
  2. java读取properties 文件信息
  3. COFF/PE文件结构
  4. 微软必应借PK谷歌突围中国搜索市场
  5. All about Performing User-Managed Database Recovery
  6. js如何判断是否在iframe中
  7. VSFTP服务——实验
  8. 首页导航点击A连接跳转并添加上背景色,
  9. Android 消息传递之Bundle的使用——实现object对象传输(二)
  10. make -j 多核并行编译 导致笔记本过热 自动关机保护