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. JavaScript -- Window-窗口坐标

    -----029-Window-窗口坐标.html----- <!DOCTYPE html> <html> <head> <meta http-equiv=& ...

  2. Tomcat学习总结(7)——Tomcat与Jetty比较

    Jetty 基本架构 Jetty目前的是一个比较被看好的 Servlet 引擎,它的架构比较简单,也是一个可扩展性和非常灵活的应用服务器. 它有一个基本数据模型,这个数据模型就是 Handler(处理 ...

  3. 【IT笔试面试题整理】反转链表

    [试题描述]定义一个函数,输入一个链表的头节点,反转该链表并输出反转后链表的头节点 [参考代码] 方法一: public static Link reverseLinkList(Link head) ...

  4. java设计模式(详)

    http://www.runoob.com/design-pattern/design-pattern-tutorial.html

  5. (转)JAVA常见面试题之Forward和Redirect的区别

    阅读目录 一:间接请求转发(Redirect) 二:直接请求转发(Forward) 用户向服务器发送了一次HTTP请求,该请求可能会经过多个信息资源处理以后才返回给用户,各个信息资源使用请求转发机制相 ...

  6. 附件十四面3D模型的自动化生成

    附件十四面的3D模型可以自动生成了 2017-10-14 刘崇军 风螺旋线 这个故事开始于大约半年前,偶然从电脑里翻到了曾经收藏的这本书<Automatic SketchUp>,英语+3D ...

  7. POJ 1061 青蛙的约会(拓展欧几里得算法求解模线性方程组详解)

    题目链接: BZOJ: https://www.lydsy.com/JudgeOnline/problem.php?id=1477 POJ: https://cn.vjudge.net/problem ...

  8. 1.C#知识点:值类型和引用类型

    一.什么是值类型?什么引用类型? 1.值类型的值是存储在栈上的.引用类型是存在堆上的.  2.值类型变量声明之后,不管是否已经分配内存,编译器在堆上为其分配内存.  3.引用类型声明的时候,这时候只在 ...

  9. 批量导出VBA工程中的Source

    在做Excel宏相关项目的开发和维护过程中,我们经常需要导出VBA中的Source,但是Excel提供的宏编辑器中只能一个文件一个文件地导出,很不方便. 下面介绍2种批量导出的方法: 1.Source ...

  10. Sql Server 与 MySql 在使用 update inner join 时的区别

    Sql Server -- 不使用别名 UPDATE tb_User SET tb_User.pass = '' FROM tb_User usr INNER JOIN tb_Address addr ...