448. Find All Numbers Disappeared in an Array Add to List
题目描述

题目分析
有个[1,n]的条件要充分利用起来。
题目代码
public class Solution {
public List<Integer> findDisappearedNumbers(int[] nums) {
List<Integer> list=new ArrayList<Integer>();
if(nums==null || nums.length==0) return list;
if(nums.length == 1 ){
list.add(nums[0]);
return list;
}
int i=0,temp=nums[0],t;
while(true){
if(temp>0){
t=nums[temp-1];
nums[temp-1]=0;
temp=t;
}
else{
i++;
if(i>=nums.length) break;
temp=nums[i];
}
}
for(i=0;i<nums.length;i++){
if(nums[i]!=0){
list.add(i+1);
}
}
return list;
}
}
448. Find All Numbers Disappeared in an Array Add to List的更多相关文章
- 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 = ...
- 【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 ...
- 448. Find All Numbers Disappeared in an Array【easy】
448. Find All Numbers Disappeared in an Array[easy] Given an array of integers where 1 ≤ a[i] ≤ n (n ...
- 448. Find All Numbers Disappeared in an Array@python
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 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 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 解题报告
题目要求 Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice a ...
随机推荐
- php课程---练习连接数据库及增删改
方式一:用php中的内置函数来做 (适用于5.1之前的版本) //1.生成连接 $conn = mysql_connect("localhost","root" ...
- 【iCore3 双核心板】例程十:RTC实时时钟实验——显示日期和时间
实验指导书及代码包下载: http://pan.baidu.com/s/1jHuZcnc iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- Portable Operating System Interface for uni-X
https://kb.iu.edu/d/agjv Short for "Portable Operating System Interface for uni-X", POSIX ...
- [转]JNIEnv解析
1.关于JNIEnv和JavaVM JNIEnv是一个与线程相关的变量,不同线程的JNIEnv彼此独立.JavaVM是虚拟机在JNI层的代表,在一个虚拟机进程中只有一个JavaVM,因此该进程的所有线 ...
- vmware centos6.5 net 配置
使用NAT模式 虚拟机网络连接使用NAT模式,物理机网络连接使用Vmnet8. 虚拟机设置里面——网络适配器,网络连接选择NAT模式. 虚拟机菜单栏—编辑—虚拟网络编辑器,选择Vmnet8 NAT模式 ...
- canvas 实现 柱状图
define([],function(){ var myChart={ init:function(options){ this.ctx = options.ctx; this.data = opti ...
- 由FutureTask的get方法靠什么机制来阻塞引发的思考
1. FutureTask的get方法靠什么机制来阻塞 看其get方法源码: /** * @throws CancellationException {@inheritDoc} */ public V ...
- 使用复合索引代替单键索引,来避免单键有null值的情况
查看原表: SQL> select count(*) from t1; COUNT(*) ---------- 3229088 SQL> select count(*) from t1 w ...
- Timer的用法
目的实现一个间隔轮询执行的功能. 从网上看到java中可以使用Timer,于是本篇文件就对自己的使用记录,进行一次记录. 主函数: package cn.test.timer; import java ...
- Web3D编程总结——3D碰撞检测初探
自己动手写一个方法比分析他人的写的方法困难很多,由此而来的对程序的进一步理解也是分析别人的代码很难得到的. 一.先来几张效果图: 1.场景中有两个半径为1的球体,蓝色线段从球心出发指向球体的“正向” ...