博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【LeetCode OJ 268】Missing Number
阅读量:4576 次
发布时间:2019-06-08

本文共 642 字,大约阅读时间需要 2 分钟。

题目链接:

题目: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;i
0) return 0; else return nums[nums.length-1]+1; } return 0; }}

转载于:https://www.cnblogs.com/jzssuanfa/p/7140540.html

你可能感兴趣的文章
learnByWork
查看>>
lua 函数
查看>>
Git的基本命令
查看>>
四平方和
查看>>
第十八周 12.27-1.2
查看>>
C# IP地址字符串和数值转换
查看>>
TCHAR和CHAR类型的互转
查看>>
常用界面布局
查看>>
C语言—— for 循环
查看>>
IBM lotus9.0测试版即将公测
查看>>
xml常用方法
查看>>
Cube Stacking(并差集深度+结点个数)
查看>>
AndroidStudio3更改包名失败
查看>>
jq 删除数组中的元素
查看>>
js URL中文传参乱码
查看>>
Leetcode 367. Valid Perfect Square
查看>>
UVALive 3635 Pie(二分法)
查看>>
win系统查看自己电脑IP
查看>>
Backup&recovery备份和还原 mysql
查看>>
一道面试题及扩展
查看>>