描述

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?

分析

日常水题。。

class Solution {
public:
int missingNumber(vector<int>& nums) {
sort(nums.begin(),nums.end());
for(int i = 0; i != nums.size(); ++i){
if(nums[i] != i)return i;
}
return nums.size();
}
};

leetcode解题报告(17):Missing Number的更多相关文章

  1. LeetCode解题报告:Linked List Cycle && Linked List Cycle II

    LeetCode解题报告:Linked List Cycle && Linked List Cycle II 1题目 Linked List Cycle Given a linked ...

  2. leetcode解题报告(2):Remove Duplicates from Sorted ArrayII

    描述 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ex ...

  3. LeetCode 解题报告索引

    最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中......                        ...

  4. LeetCode解题报告汇总! All in One!

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 把自己刷过的所有题目做一个整理,并且用简洁的语言概括了一下思路,汇总成了一个表格. 题目 ...

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

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

  6. LeetCode 解题报告--202Happy Number

    1 题目描述 Write an algorithm to determine if a number is "happy". A happy number is a number ...

  7. LeetCode解题报告—— Container With Most Water & 3Sum Closest & Letter Combinations of a Phone Number

    1.  Container With Most Water Given n non-negative integers a1, a2, ..., an, where each represents a ...

  8. leetcode解题报告(15):Third Maximum Number

    描述 Given a non-empty array of integers, return the third maximum number in this array. If it does no ...

  9. LeetCode解题报告—— Number of Islands & Bitwise AND of Numbers Range

    1. Number of Islands Given a 2d grid map of '1's (land) and '0's (water), count the number of island ...

随机推荐

  1. Linux下交换文件说明

    vi写文件,没有保存就关闭,会自动生成一个后缀为.swp的交换文件(隐藏文件),保存了前面写的内容 先利用R恢复,在删除这个交换文件 涉及到的命令 ls –a rm .xxx.swap -rf 

  2. Fabric交易流程

    (内容可能有些乱,请见谅,日后会对格式进行整理!) #### 在1.0及以后的版本中,客户端应用会先向Fabric CA申请用户所需要的Fabric中的准入证书,用于签名提案以及交易,然后由客户端(A ...

  3. 设置Echarts图例位置

    只需要修改如下几个示数即可: ①x:可以选择左(left).右(right).居中(center)②y:可以选择左(left).右(right).居中(center)③padding:[0,30,0, ...

  4. 海思SDK 与各芯片对照

    本文链接:https://blog.csdn.net/liuxizhen2009/article/details/84261221 海思SDK不对外开放. 海思35系列sdk Hi3507   Hi3 ...

  5. 在论坛中出现的比较难的sql问题:29(row_number函数 组内某列的值连续出现3次标记出来)

    原文:在论坛中出现的比较难的sql问题:29(row_number函数 组内某列的值连续出现3次标记出来) 在论坛中,遇到了不少比较难的sql问题,虽然自己都能解决,但发现过几天后,就记不起来了,也忘 ...

  6. Python、PyCharm、Django框架安装

    一.下载Python环境 1.1 下载Python环境,以下网址: https://www.python.org/downloads/release/python-373/ 下载安装包: 1.2点击安 ...

  7. k8s 开源web操作平台

    https://kuboard.cn/install/install-dashboard.html kuborad

  8. Go part 8 并发编程,goroutine, channel

    并发 并发是指的多任务,并发编程含义比较广泛,包含多线程.多进程及分布式程序,这里记录的并发是属于多线程编程 Go 从语言层面上支持了并发的特性,通过 goroutine 来完成,goroutine ...

  9. Hadoop HA 搭建

    Hadoop HA 什么是 HA HA是High Available缩写,是双机集群系统简称,指高可用性集群,是保证业务连续性的有效解决方案,一般有两个或两个以上的节点,且分为活动节点及备用节点.通常 ...

  10. 部署Java项目到阿里云服务器(Ubuntu16.04 64位)

    生成Jar包 1.进入到项目所在的路径下,打开cmd命令控制台,使用如下命令打包项目. mvn package --前提将项目中使用的maven配置到系统的环境变量中 2.打包完成的jar包在项目目录 ...