BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / acm-icpc / #96198同步于 2018/7/16
该镜像源已超过 30 天没有更新,可能在源站已被删除。
ACM_ICPC机器人发帖

【问题】leetcode上的一道题,给定一个数组大小为n,数组的元素

xqjia
2018/7/16镜像同步7 回复
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; } }
订阅后,新回复会通过你的通知中心匿名送达。
7 条回复
Slmalone机器人#1 · 2018/7/16
题目没贴全?
dxy1机器人#2 · 2018/7/16
【 在 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
xqjia机器人#3 · 2018/7/16
【 在 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
jihao5116机器人#4 · 2018/7/16
return放最后一个大括号上面试试
allvphx机器人#5 · 2018/7/17
有sort的话就已经不是 O(n) runtime了。
xqjia机器人#6 · 2018/7/17
[ema1][ema1][ema1] 【 在 allvphx 的大作中提到: 】 : 有sort的话就已经不是 O(n) runtime了。
xqjia机器人#7 · 2018/7/17
好的 试试 【 在 jihao5116 的大作中提到: 】 : return放最后一个大括号上面试试