448. Find All Numbers Disappeared in an Array Add to List
Posted hellozay
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章
Leetcode 448. Find All Numbers Disappeared in an Array
448. Find All Numbers Disappeared in an Array
448. Find All Numbers Disappeared in an Array
448. Find All Numbers Disappeared in an Array