题意:

  给一个含有n个整数的数组,数组中的元素应该是0~n。现在缺了其中某1个,找出缺少的那个整数?

思路:

  0~n的总和是可以直接计算的,而缺少的那个就是sum减去数组的和。

 int missingNumber(vector<int>& nums)
{
int sum=;
for(int i=; i<nums.size(); i++)
sum+=i+-nums[i];
return sum;
}

AC代码

LeetCode Missing Number (简单题)的更多相关文章

  1. HDU 5166 Missing number 简单数论

    Missing number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) [ ...

  2. PAT 1144 The Missing Number[简单]

    1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...

  3. [LeetCode] Missing Number 丢失的数字

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

  4. [LeetCode] Missing Number (A New Questions Added Today)

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

  5. (leetcode)Missing Number

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

  6. LeetCode——Missing Number

    Description: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one t ...

  7. 力扣485. 最大连续1的个数-C语言实现-简单题

    题目 [题目传送门] 给定一个二进制数组, 计算其中最大连续1的个数. 示例 1: 输入: [1,1,0,1,1,1] 输出: 3 解释: 开头的两位和最后的三位都是连续1,所以最大连续1的个数是 3 ...

  8. PAT-1144(The Missing Number)set的使用,简单题

    The Missing Number PAT-1144 #include<iostream> #include<cstring> #include<string> ...

  9. leetcode简单题6

    今天的华师 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, fro ...

随机推荐

  1. pure css简单组件,借鉴bootstrap

    <!doctype html> <html> <head> <meta http-equiv="Content-type" content ...

  2. 【Java】NIO中Selector的创建源码分析

    在使用Selector时首先需要通过静态方法open创建Selector对象 public static Selector open() throws IOException { return Sel ...

  3. java 提取(解压)rar文件中特定后缀的文件并保存到指定目录

    内容简介 本文主要介绍使用junrar来提取rar压缩文件中特定后缀(如:png,jpg)的文件并保存到指定目录下. 支持v4及以下版本压缩文件,不支持v5及以上. 在rar文件上右键,查看属性,在压 ...

  4. 《OD学spark》20161022

    一.Spark Core 1. 什么是Spark Shuffle Wide Dependencies *ByKey: groupByKey,reduceByKey 关联操作:join,cogroup ...

  5. UVA307 Sticks

    题意:一组等长的木棒,将它们随机的砍掉,得到若干根小木棍, 每一节小棍的长度都不超过50个单位.然后想把这些木棍拼接起来,恢复到裁剪前的状态, 但忘记了初始时有多少木棒以及木棒的初始长度.计算木棒的可 ...

  6. html的Vue.js框架概述

    前端的三大框架: Augular.js          由Google的研发团队最先写出 React.js            由facebook的团队继Augular.js之后写出 Vue.js ...

  7. PHP与thinkphp中var_dump()打印数组显示不全问题

    在我们进行php开发的时候,经常会使用var_dump()函数进行数组的打印,以方便我们程序的调试,而有时候我们在进行多维数组打印的时候会发现多维数组打印不全,有些地方被…代替,这就是我们php配置的 ...

  8. day04 ---Linux安装Python3

    如何linux上安装python3 1.下载源代码,方式有2个, 1.在windows上下载,下载完成后,通过lrzsz工具,或者xftp工具,传输到linux服务器中 2.在linux中直接下载 c ...

  9. CSS(二)关于position

    position有五种取值 前排说一个问题,2017-10-8日更新: transform会影响定位,导致fixed降级为absolute.无论是transform:translate(),scale ...

  10. NppFTP小插件的使用

    大家在Linux系统中配置运行环境时,一定会遇到相关配置文件的修改,虽说在Linux系统中可以使用vi,vim的命令进行文本编辑,但是操作起来还是没有在Windows系统中用的爽,特别是操作大文本量的 ...