The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another number in the set, which results in repetition of one number and loss of another number.

Given an array nums representing the data status of this set after the error. Your task is to firstly find the number occurs twice and then find the number that is missing. Return them in the form of an array.

Example 1:

Input: nums = [1,2,2,4]
Output: [2,3]

Note:

  1. The given array size will in the range [2, 10000].
  2. The given array's numbers won't have any order.
class Solution {
public:
vector<int> findErrorNums(vector<int>& nums) {
vector <int> ans;
for (int i = ; i < nums.size(); i++) {
int index = abs(nums[i]) - ;
if (nums[index] > ) {
nums[index] *= -;
}
else {
ans.push_back(index + );
}
}
for (int i = ; i < nums.size(); i++) {
if (nums[i] > ) {
ans.push_back(i + );
}
}
return ans;
}
};

求集合s中重复出现的数字、缺失的数字

最新文章

  1. 利用AOP与ToStringBuilder简化日志记录
  2. 订货(bzoj 2424)
  3. CSS三种写法的优先级
  4. SQL多表查询
  5. C++ int与string的转化
  6. C语言 文件操作4--文件结构体FILE的理解以及缓冲区再讲
  7. docker:从 tomcat 容器连接到 mysql 容器
  8. 华东交通大学2016年ACM“双基”程序设计竞赛 1001
  9. C# 导出一个控件的矢量图
  10. something: 重构、正则、vim -- clwu
  11. java答疑
  12. Longest Palindromic Substring-----最长回文子串
  13. Work 2(演讲类) (2017.06.29)
  14. Linux指令--touch
  15. Flex弹出窗口请求Action函数
  16. Python3 标准库学习
  17. 使用 TRESTClient 与 TRESTRequest 作为 HTTP Client(转)
  18. Exception in thread &quot;main&quot; java.lang.NoSuchMethodError: scala.Predef$.refArrayOps([Ljava/lang/Object;)Lscala/collection/mutable/ArrayOps;
  19. Django详解之models操作
  20. 【解决】win10 启用系统保护 灰色 不可选 的解决办法

热门文章

  1. [SoapUI] 配置默认环境的properties
  2. OSGi karaf scheduler
  3. boosting_bagging
  4. 测试这个才可以打包 我的PYQt matplotlib numpy 等程序
  5. 2018.08.02 洛谷P3355 骑士共存问题(最小割)
  6. 右值引用和std::move函数(c++11)
  7. @WebService @WebMethod 详解
  8. 让tableView的某行移动到tableView的某位置
  9. oracl中的大数据类型clob
  10. PAT甲 1048. Find Coins (25) 2016-09-09 23:15 29人阅读 评论(0) 收藏