描述

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】Shell批量修改文件名

    修改文件名,替换中间字符: 例如:ABC_define_EFG.jpg,要把中间的define替换成argument: 用如下脚本即可: for var in *; do mv "$var& ...

  2. .NET Standards

    .net的创始者们在一开始的时候,就意识到了他们的编程技术可以用在不通的操作系统和不同类型的cpu上.他们改进了20世纪90年代编程语言实现技术.最主要的一条是,不同的编程语言对应统一个运行时,及CL ...

  3. Suricata Rules

    Suricata Rules https://redmine.openinfosecfoundation.org/projects/suricata/wiki/Suricata_Rules https ...

  4. 算法题:购买n个苹果,苹果6个一袋或者8个一袋,若想袋数最少,如何购买?

    这是面试一家公司java实习生的算法题,我当时把代码写出来了,但是回学校之后搜索别人的算法,才发现自己的算法实在是太简陋了呜呜呜 我的算法: public void buy(int n){ int m ...

  5. vue复制textarea文本域内容到粘贴板

    vue实现复制内容到粘贴板   方案:找到textarea对象(input同样适用),获取焦点,选中textarea的所有内容,并调用document.execCommand("copy&q ...

  6. 远程 Linux(Ubuntu 18)添加字体

    安装 xshell与xftp 连接xshell 点击 xshell上方工具栏中的xftp图标, 自动连接xftp linux下创建字体目录 su cd / cd usr/share/fonts mkd ...

  7. vue 鼠标移入移出事件执行多次(尤其ie)

    来自:https://www.cnblogs.com/myfirstboke/p/9150809.html  侵删 <p @mouseover="over($event)" ...

  8. ORA-28547: connection to server failed, probable Oracle Net admin error

    现象 C:\Users\Administrator>sqlplus scott/tiger@192.168.1.11:1521/orcl SQL*Plus: Release 11.2.0.4.0 ...

  9. vue框架之脚手架(vue-cli)的使用

    前期准备 1.在使用之前需要安装node.js,https://nodejs.org/dist/latest-v8.x/ 2.下载之后在cmd中测试 node -v npm -v 如图上即可 3.下载 ...

  10. Linux动态连接器

    转自:Chapter 9. Dynamic Linking 参考:Linux动态链接器 Linux加载启动可执行程序的过程(一)内核空间加载ELF的过程 Linux加载启动可执行程序的过程(二)解释器 ...