题目链接:
题目:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n
, find the one that is missing from the array.
For example,
Given nums =[0, 1, 3]
return 2
. Note:
Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?解题思路:题意为给定一个包括n个不反复的数的数组。从0,1,2...n,找出数组中遗漏的那个数。
演示样例代码例如以下:
public class Solution{ public int missingNumber(int[] nums) { //首先对数组进行排序 Arrays.sort(nums); int startData=nums[0]; for(int i=1;i0) return 0; else return nums[nums.length-1]+1; } return 0; }}