[抄题]:

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. bzoj 2657 旅游

    Written with StackEdit. Description 到了难得的暑假,为了庆祝小白在数学考试中取得的优异成绩,小蓝决定带小白出去旅游~~ 经过一番抉择,两人决定将\(T\)国作为他们 ...

  2. mysql锁之Next-Key Locks

    一个Next-key锁结合了行锁和gap锁. InnoDB执行一个行级别锁在这样的一个途径,那就是它搜索或者扫描一个表索引时,它设置共享或者独占锁在它遭遇的索引记录上.于是,行级锁是真实的行记录锁.一 ...

  3. Fillder手机抓包的使用

    1.Fillder下载地址: http://www.onlinedown.net/soft/73207.htm 2.网络设置 手机和电脑需链接网络相同 3.fillder设置 3.1打开fillder ...

  4. 数据库连接配置 app.config web.config

    通过ADO.Net连接程序和SQLServer数据库的连接字符串: connectionString ="server=(local);database=Demo;integrated se ...

  5. LeetCode Path Sum IV

    原题链接在这里:https://leetcode.com/problems/path-sum-iv/description/ 题目: If the depth of a tree is smaller ...

  6. 笔记:开源协议 Apache 2 和 GPL 兼容

    笔记:开源协议 Apache 2 和 GPL 兼容 Apache 2 和 GPL v3 兼容. GPL 分了很多版本,LGPL 为最宽松的 GPL,而 AGPL 为最严格的 GPL 协议. Linux ...

  7. 客户端如何调用WebService并且POST数据

    直接上代码 using System; using System.Collections.Generic; using System.Linq; using System.Text;using Sys ...

  8. hbase使用中需要注意一些问题

    接触hbase已经两年之久,但是真正的在实际项目中使用却只有半年的时间,使用过程中,一方面在在为hbase强大的性能兴奋之余,另一方面却也给我和我的团队造成了很多的麻烦,起初在使用我的水平也就停留在会 ...

  9. vim中多行注释和多行删除命令

      1.多行注释:   1. 首先按esc进入命令行模式下,按下Ctrl + v,进入列(也叫区块)模式;   2. 在行首使用上下键选择需要注释的多行;   3. 按下键盘(大写)“I”键,进入插入 ...

  10. mysql索引之二:数据结构及算法原理

    摘要 本文以MySQL数据库为研究对象,讨论与数据库索引相关的一些话题.特别需要说明的是,MySQL支持诸多存储引擎,而各种存储引擎对索引的支持也各不相同,因此MySQL数据库支持多种索引类型,如BT ...