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]
    public List<Integer> findDisappearedNumbers(int[] nums) {
List<Integer> ret = new ArrayList<Integer>(); for(int i = ; i < nums.length; i++) {
int val = Math.abs(nums[i]) - ;
if(nums[val] > ) {
nums[val] = -nums[val];
}
} for(int i = ; i < nums.length; i++) {
if(nums[i] > ) {
ret.add(i+);
}
}
return ret;
}

Leetcode-448. Find All Numbers Disappeared in an Array(solve without extra space easy)的更多相关文章

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

  2. leetcode 448. Find All Numbers Disappeared in an Array -easy (重要)

    题目链接: https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/description/ 题目描述: Give ...

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

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

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

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

  7. LeetCode 448. Find All Numbers Disappeared in an Array找到所有数组中消失的元素

    题目 给定一个范围在 1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次. 找到所有在 [1, n] 范围之间没有出现在数组中的数字. 您能 ...

  8. [LeetCode] 448. Find All Numbers Disappeared in an Array 找到数组中消失的数字

    题目描述 给定n个数字的数组,里面的值都是1-n,但是有的出现了两遍,因此有的没有出现,求没有出现值这个数组中的值有哪些. 要求不能用额外的空间(除了返回列表之外),时间复杂度n 思路 因为不能用额外 ...

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

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

随机推荐

  1. javascript 高级程序设计 九

    JS 面向对象的程序设计思想(1)深入理解JS对象 1.js的中没有OO语言中的'类'的概念.ECMAjs中把对象定义为:‘无序属性的集合,其属性可以包含基本值,对象或函数’. 2.ECMAScrip ...

  2. python基础之Day4

    流程判断 一.if 1.语法一 各条件都执行 if条件1: if条件2: if条件3: 2.语法二 if多分支,自上而下执行,一旦满足条件,后面代码即使满足条件也不会执行 if条件1: elif条件2 ...

  3. 部署描述符(web.xml)和标注(annotation)

    部署描述符(web.xml) 详细信息可在http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html上下载web- ...

  4. [Robot Framework] 怎么做数学运算?

    运用BuiltIn里面的Set Variable

  5. 论坛:Error:No result defined for action cn.itcast.oa.view.action.TopicAction and result

    使用了<s:hidden name="forumId" value="#forum.id"/> 可以改为: <s:hidden name=&q ...

  6. python 的文件操作

    二进制用法 f=open('test.txt','wb') f.write("汉字\r\n".encode('UTF-8')) f.write("hello". ...

  7. cocos jsb工程转html 工程

    1 CCBoot.js prepare方法:注掉下面这行,先加载moduleConfig中的脚本后加载user脚本 //newJsList = newJsList.concat(jsList); // ...

  8. js jquery 取得周月年时间

    function formatDate(date) { var myyear = date.getFullYear(); var mymonth = date.getMonth() + 1; var ...

  9. sim卡联系人name为空的问题。

    1,之前的版本出现Bug:新建name为空的sim卡联系人,无法删除. 解决: 2,而后的版本出现新Bug:新建name不为空,Num不为空的sim卡联系人,然后编辑sim卡联系人,将Name清空,无 ...

  10. samtools flagstat

    samtools flagstat命令简介: 统计输入文件的相关数据并将这些数据输出至屏幕显示.每一项统计数据都由两部分组成,分别是QC pass和QC failed,表示通过QC的reads数据量和 ...