[抄题]:

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.

Example 1

Input: [3,0,1]
Output: 2

Example 2

Input: [9,6,4,2,3,5,7,0,1]
Output: 8

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[一个数还不是0]返回0:下次多想想一个数的情况

[思维问题]:

[一句话思路]:

就是for一遍

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

设置了一个返回值result,不知道怎么初始化。倒不如直接{里面出错结果} + 外面默认正常结果

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

直接{里面出错结果} + 外面默认正常结果

[复杂度]:Time complexity: O(n) Space complexity: O(1 就地for循环)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

First Missing Positive 越讨论越复杂的一道题

Find the Duplicate Number 快慢指针:好吧可以往这个方向思考

[代码风格] :

class Solution {
public int missingNumber(int[] nums) { //ini = sort
Arrays.sort(nums); //cc
if (nums[0] != 0) {
return 0;
} //for
for (int i = 0; i < nums.length - 1; i++) {
if (nums[i + 1] != nums[i] + 1) {
return nums[i] + 1;
}
} //return
return nums.length;
}
}

268. Missing Number序列中遗失的数字的更多相关文章

  1. &lt;LeetCode OJ&gt; 268. Missing Number

    268. Missing Number Total Accepted: 31740 Total Submissions: 83547 Difficulty: Medium Given an array ...

  2. [LeetCode] 268. Missing Number ☆(丢失的数字)

    转载:http://www.cnblogs.com/grandyang/p/4756677.html Given an array containing n distinct numbers take ...

  3. 268 Missing Number 缺失的数字

    给出一个包含 0, 1, 2, ..., n 中 n 个数的序列,找出 0 .. n 中没有出现在序列中的那个数.案例 1输入: [3,0,1]输出: 2案例 2输入: [9,6,4,2,3,5,7, ...

  4. LeetCode 268. Missing Number缺失数字 (C++/Java)

    题目: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is mi ...

  5. 268. Missing Number@python

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  6. 【LeetCode】268. Missing Number

    Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one ...

  7. LeetCode 268. Missing Number (缺失的数字)

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  8. [LeetCode] 268. Missing Number 缺失的数字

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  9. 268. Missing Number -- 找出0-n中缺失的一个数

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

随机推荐

  1. 让cocos h5里的文字可以在手机上被长按复制

    更改CCBoot.js代码: // Adjust mobile css settings if (cc.sys.isMobile) { var fontStyle = document.createE ...

  2. DEV控件 皮肤问题

    今天用cnPack清理了下整个工程的引用单元,清理完,问题来了,TcxPageControl不透明了. 折腾了一会,找到原因,清理单元时将dxSkinscxPCPainter也清掉了,导致皮肤无法正常 ...

  3. git自用笔记

    同步远程库:git clone xxx.git [filename] git ls-files: 查看已经添加进暂存区的文件. 在commit前修改一个文件后(假设名为:xxx.file),想撤销时, ...

  4. retful上传文件php的实现

    项目中要使用restful上传文件到服务器,一直不能成功,后生成相关串后在postman中上传成功,利用这个工具生成php curl的代码,后逐步比对产生以下代码. /**     * 上传文件    ...

  5. Toolbar使用

    原文地址 http://www.cnblogs.com/Dentist/p/4370176.html Android4.0出现的Actionbar提供了同意方便的导航管理.很大程度的统一了Androi ...

  6. 20位活跃在Github上的国内技术大牛

    登录|注册     leon-这个程序员不闷骚的博客 喜欢leon,有追求有原则有爱心的杀手,做一个有追求的程序员,代码是程序员的朋友,虽然没有热情,但是非常忠实.希望拥有一身绝世武功,再配一把绝世好 ...

  7. python中的enumerate函数用于遍历序列中的元素以及它们的下标

    enumerate 函数用于遍历序列中的元素以及它们的下标: >>> for i,j in enumerate(('a','b','c')): print i,j 0 a1 b2 c ...

  8. 注册驱动时如何调用probe函数 ?

    platform_driver_register       driver_register             bus_add_driver    //把驱动放入总线的驱动链表里         ...

  9. log4net 使用总结- (1)在ASP.NET MVC 中使用

    1. 去官网下载log4net.dll,增加引用到站点下(你也可以通过nuget 安装) http://logging.apache.org/log4net/download_log4net.cgi ...

  10. Web验证码图片的生成-基于Java的实现

    验证码图片是由程序动态产生的,每次访问的内容都是随机的.那么如何采用程序动态产生图片,并能够显示在客户端页面中呢?原理很简单,对于java而言,我们首先开发一个Servlet,这个Servlet的任务 ...