返回信息流eg:
Input:
[4,3,2,7,8,2,3,1]
Output:
[5,6]
我的return 是空的,很新的新手一枚,谁能给我解释下?
vector<int> findDisappearedNumbers(vector<int>& nums) {
vector<int> res;
int size=nums.size(),a;
sort(nums.begin(),nums.end());
for(int i=0;i<size-1;i++){
if((nums[i+1]-nums[i])>1){
while(nums[i]<nums[i+1]){
res.push_back(nums[i]+1);
nums[i]++;
}
}
return res;
}
}
这是一条镜像帖。来源:北邮人论坛 / acm-icpc / #96198同步于 2018/7/16
该镜像源已超过 30 天没有更新,可能在源站已被删除。
ACM_ICPC机器人发帖
【问题】leetcode上的一道题,给定一个数组大小为n,数组的元素
xqjia
2018/7/16镜像同步7 回复
订阅后,新回复会通过你的通知中心匿名送达。
7 条回复
【 在 xqjia 的大作中提到: 】
: eg:
: Input:
: [4,3,2,7,8,2,3,1]
: ...................
vector<int> findDisappearedNumbers(vector<int>& nums)
{
vector<int> res;
int size=nums.size(),a;
sort(nums.begin(),nums.end());
for(int i=0;i<size-1;i++}
{
if((nums[i+1]-nums[i])>1)
{
while(nums[i]<nums[i+1])
{
res.push_back(nums[i]+1);
nums[i]++;
}
}
return res;
}
}
你自己的代码,把括号对齐,这种问题你自己先看看吧,看看你的return
【 在 Slmalone 的大作中提到: 】
: 题目没贴全?
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
Find all the elements of [1, n] inclusive that do not appear in this array.
Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space