Array-Leetcode
来源:互联网 发布:澳门网络现金赌博 编辑:程序博客网 时间:2024/05/16 09:25
268. 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) { sort(nums.begin(),nums.end()); int value[nums.size()]={0},j=0,count=0; for(int i=0;i<nums.size();i++) { if(j<nums.size()&&i<=nums[j]) { if(nums[j]!=i) { value[count]=i; count++; } else { j++; } } } if(count==0) { return nums.size(); } else { for(int i=0;i<nums.size();i++) { return value[i]; } } }};
0 0
- [leetcode][array] Rotate Array
- LeetCode:Array
- Array-Leetcode
- Array-Leetcode
- Array-Leetcode
- Array-Leetcode
- Array-Leetcode
- Array-Leetcode
- Array-Leetcode
- Array-Leetcode
- Array-Leetcode
- Array-Leetcode
- Array-Leetcode
- LeetCode Array
- Leetcode-array
- leetcode array
- [leetcode]Array
- Leetcode - Array - Merge Sorted Array
- 在Unity的后处理shader中通过屏幕像素坐标和深度贴图反推世界坐标
- 安卓页面跳转-Intent
- 线性表
- vmware卸载不完全后遇到的安装问题
- Linux基础——chattr 文件或者目录的隐藏属性
- Array-Leetcode
- HDU2084
- HttpUrlconnection 实现大文件分片断点上传,支持Https
- POJ 2632 Crashing Robots (模拟)
- 开博感言
- 前端总结·基础篇·CSS(二)视觉
- 并发模式(二)Master-Worker模式
- 6.13、旁系亲属与级别内导航
- python代码转matlab代码的注意点【不断更新...】