1、题目描述

2.问题分析

使的 A[i] = i+1 ,最后检查不满足这个条件的i+1 .即为缺失的值。

3.代码

 vector<int> findDisappearedNumbers(vector<int>& nums) {
for( int i = ; i < nums.size() ; ++i ){
if( nums[i] != nums[ nums[i] - ] ){
swap( nums[i] , nums[nums[i] - ] );
i--;
}
}
vector<int> result ;
for( int i = ; i < nums.size() ; i++){
if( nums[i] != i+ )
result.push_back( i+ );
}
return result ;
}

LeetCode题解之Find All Numbers Disappeared in an Array的更多相关文章

  1. 【leetcode】448. Find All Numbers Disappeared in an Array

    problem 448. Find All Numbers Disappeared in an Array solution: class Solution { public: vector<i ...

  2. LeetCode算法题-Find All Numbers Disappeared in an Array(Java实现)

    这是悦乐书的第232次更新,第245篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第99题(顺位题号是448).给定一个整数数组,其中1≤a[i]≤n(n =数组的大小) ...

  3. 【LeetCode】448. Find All Numbers Disappeared in an Array 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 方法一:暴力求解 方法二:原地变负做标记 方法三:使用set ...

  4. [leetcode]python 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 ...

  5. LeetCode——Find All Numbers Disappeared in an Array

    LeetCode--Find All Numbers Disappeared in an Array Question Given an array of integers where 1 ≤ a[i ...

  6. leetcode之Find All Numbers Disappeared in an Array

    问题来源:Find All Numbers Disappeared in an Array 很久没有刷题了,感觉大脑开始迟钝,所以决定重拾刷题的乐趣.一开始不要太难,选一些通过率高的题目做,然后就看到 ...

  7. 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 ...

  8. LeetCode_448. Find All Numbers Disappeared in an Array

    448. Find All Numbers Disappeared in an Array Easy Given an array of integers where 1 ≤ a[i] ≤ n (n  ...

  9. 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 = ...

随机推荐

  1. SQL SERVICE日志收缩

    ALTER DATABASE 数据库SET RECOVERY SIMPLE WITH NO_WAIT;ALTER DATABASE 数据库SET RECOVERY SIMPLE; --简单模式DBCC ...

  2. PLSQL Developer概念学习系列之如何正确登录连接上Oracle(图文详解)

    不多说,直接上干货! 进入PLSQL Developer 1.双击 2.得到 比如,我这里安装的是 全网最详细的Windows系统里Oracle 11g R2 Database服务器端(64bit)的 ...

  3. JAVA 利用Dom4j实现英语六级词汇查询 含演示地址

    要求 必备知识 基本了解JAVA编程知识,DOM基础. 开发环境 MyEclipse10 演示地址 演示地址     通过前面几天的学习,现在基本掌握了JAVA操作DOM方面的知识,现在来一个小DEM ...

  4. NIO 基础之 Buffer

    文章目录 1. 概述 2. 基本属性 3. 创建 Buffer 3.1 关于 Direct Buffer 和 Non-Direct Buffer 的区别 4. 向 Buffer 写入数据 5. 从 B ...

  5. Redhat6.8下安装Oracle11gR2

    Step1.配置本地yum源,方便安装依赖包 df -h 补充: df命令查看 linux系统磁盘空间以及使用情况,-h代表方便阅读方式显示  :/dev/sr0为光驱设备名 mkdir cdrom ...

  6. Solr 清空数据的简便方法

    1. 首先访问你的 core,然后点击左侧的 Documents 2. 在 documents type 选择 XML 3. documents 输入下面语句 <delete><qu ...

  7. C#语法之特性

    在项目中经常可以看到在类属性上面有一个[]的东西,今天讲的东西就是它,它英文名是Attribute,中文名是特性. 一.什么是特性? 首先,我们肯定Attribute是一个类,下面是msdn文档对它的 ...

  8. 呼叫WCF Service的方法出现Method not allowed异常

    asp.net mvc练习程序,经常性在家里电脑,笔记本或是公司的电脑之间拷贝与粘贴,如果忘记携带最新的练习程序,一些小功能只能重新写了.如前一篇<ASP.NET MVC呼叫WCF Servic ...

  9. C# winform 无边框 窗体的拖动

    当船体设置为FormborderStyle='none' [DllImport("user32.dll")] public static extern bool ReleaseCa ...

  10. Spring基础(7) : Bean的名字

    1.普通bean是用id标志,context.getBean时传入名称即可获得. <bean id="p" class="com.Person"/> ...