leetcode-Missing Number
来源:互联网 发布:2016年双11淘宝销售额 编辑:程序博客网 时间:2024/06/06 17:29
Difficulty: Medium
Given an array containing n distinct numbers taken from0, 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) { if(nums.empty()) return -1; int size=nums.size()/32+1; int bitmap[size]; fill(bitmap,bitmap+size,0); int maxNum=nums[0]; for(auto &e:nums){ bitmap[e/32]|=(1<<(e%32)); maxNum=max(e,maxNum); } for(int i=0;i<maxNum;++i){ if(bitmap[i/32]&(1<<(i%32))) continue; else return i; } return maxNum+1; }};
0 0
- 【LeetCode】268 Missing Number
- [leetcode] 268.Missing Number
- [leetcode][math] Missing Number
- [LeetCode] Missing Number
- Leetcode -- Missing Number
- 【leetCode】Missing Number
- [Leetcode]Missing Number
- leetcode Missing Number
- 【leetcode】268. Missing Number
- [leetcode] Missing Number
- LeetCode(268)Missing Number
- Leetcode: Missing Number
- LeetCode之Missing Number
- LeetCode Missing Number
- [leetcode 268]Missing Number
- leetcode--Missing Number
- leetCode #286 Missing Number
- Leetcode 286 : Missing Number
- Ubuntu环境下sublime3 nodejs安装与插件配置
- 蓝懿ios 技术内容和心得交流分享 11.5 控件
- opencv3 确定图像强角点-goodFeaturesToTrack函数-滚动条
- cocos code ide--js config.json文件结构
- Solr部署如何启动
- leetcode-Missing Number
- Web工程阶段性总结
- opencv3 实现Harris角点检测:cornerHarris函数
- MJRefresh-- iOS下拉刷新第三方类库
- Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
- SVM入门(九)松弛变量(续)
- opencv3 实现Harris角点检测:cornerHarris函数-滚动条
- 黑马程序员——集合类(一)
- 用C代码来玩“藕式结构”中的本地过程调用和远程过程调用