LeetCode:Missing Number
2015-08-28 21:34
232 查看
Given an array containing n distinct numbers taken from
For example,
Given nums =
Note:
Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?
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()); int i; for(i=0;i<nums.size();i++) { if(nums[i]!=i) { return i; } else continue; } return i; } };
相关文章推荐
- linux kernel的中断子系统之:softirq
- VC CFont 用法
- 用户研究
- Python 各种集合内置方法的时间复杂度
- hdoj 4289 Control 【拆点 求最小割】
- POJ 2182 Lost Cows (线段树)
- 文本属性Attributes
- Java泛型中E、T、K、V等的含义
- 贝叶斯算法 mapreduce实现
- 嵌入式Linux内核制作
- POJ2096——概率DP——Collecting Bugs
- LAMP--简单篇
- TCP 的那些事儿(下)
- 逻辑回归(LR)算法java实现
- LeetCode(237) Delete Node in a Linked List
- 将树莓派变成一个web服务器(2):Nginx+Flask+uWSGI部署全过程
- 【Linux高频命令专题(1)】sort
- S3C2440 温度传感器ds18b20的驱动编写与测试
- 在由N个正整数的集合S中,找出最大元素M,满足M=A + B,其中A,B都是集合S中元素
- 如何写一本书?