(leetcode)Missing Number
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) {
int len = nums.size();
int sum = len*(len+)/;
for(int i = ;i<len;++i)
{
sum -= nums[i];
}
return sum;
}
};
(leetcode)Missing Number的更多相关文章
- [LeetCode] Missing Number 丢失的数字
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- [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 ...
- LeetCode——Missing Number
Description: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one t ...
- LeetCode Missing Number (简单题)
题意: 给一个含有n个整数的数组,数组中的元素应该是0-n.现在缺了其中某1个,找出缺少的那个整数? 思路: 0-n的总和是可以直接计算的,而缺少的那个就是sum减去数组的和. int missing ...
- 【LeetCode】268. Missing Number
Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one ...
- <LeetCode OJ> 268. Missing Number
268. Missing Number Total Accepted: 31740 Total Submissions: 83547 Difficulty: Medium Given an array ...
- [LeetCode] Single Number 单独的数字
Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...
- [LintCode] Find the Missing Number 寻找丢失的数字
Given an array contains N numbers of 0 .. N, find which number doesn't exist in the array. Example G ...
- Leetcode-268 Missing Number
#268. Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find ...
随机推荐
- JavaScript中toStirng()与Object.prototype.toString.call()方法浅谈
toStirng()与Object.prototype.toString.call()方法浅谈 一.toString()是一个怎样的方法?它是能将某一个值转化为字符串的方法.然而它是如何将一个值从一种 ...
- 常用移动web开发框架研究分析
纯粹的总结一下移动web开发框架,移动web开发框架有jQuery Mobile .Sencha Touch等等,他们都来源于web开发,是成熟的框架,jQuery Mobile出自于jQuery家族 ...
- 【BZOJ】 1007: [HNOI2008]水平可见直线(凸壳)
http://www.lydsy.com/JudgeOnline/problem.php?id=1007 一开始我贪心的写了下,当然全wa了.. 这题看了题解感觉很简单. 首先什么情况才能看到呢? w ...
- Qt SizePolicy 属性
控件的sizePolicy说明控件在布局管理中的缩放方式.Qt提供的控件都有一个合理的缺省sizePolicy,但是这个缺省值有时不能适合 所有的布局,开发人员经常需要改变窗体上的某些控件的sizeP ...
- Ubuntu 14.04 使用的一些笔记
1. 今天下载了安卓的2.3.5的源代码,解压tar的时候,发现一个错误中断了解压过程: could not create the hard link file, 看了一下基本上都是每个主目录下的 . ...
- HDU 1058 优先队列or堆
本来应当是一道优先队列或者堆的题 因为每个数都应该是已经得到的数*2 *3 *5 *7而得到的 但是 2*7 大于 3*2 这就必须保证每次取得都是没有拿过的最小的数 但是它主动降低难度在样例里卖了个 ...
- 【军哥谈CI框架】之入门教程之第二讲:分析CI结构和CI是怎么工作的
[军哥谈CI框架]之入门教程之第二讲:分析CI结构和CI是怎么工作的 之入门教程之第二讲:分析CI结构和CI是如何工作的大家好!上一节,我们共同部署了一个CI网站,做到这一点非常简单,但是,亲们, ...
- Xamarin 示例Standard Controls报错:xamarin Failed to compile interface file. See Build Output for details
Standard Controls 示例下载地址: http://developer.xamarin.com/content/StandardControls/ Xamarin官网上的IOS示例“St ...
- JS Questions:Front-end Developer Interview Questions
Explain event delegation Event delegation allows us to attach a single event listener, to a parent e ...
- jquery循环绑定事件
<html> <head> <title></title> <script type="text/javascript" sr ...