problem

645. Set Mismatch

题意:

solution1:

统计每个数字出现的次数了,然后再遍历次数数组,如果某个数字出现了两次就是重复数,如果出现了0次,就是缺失数。

注意:如何统计每个数字出现的次数;

class Solution {
public:
vector<int> findErrorNums(vector<int>& nums) {
vector<int> res(, ), cnt(nums.size(), );
for(auto num:nums) ++cnt[num-];
for(int i=; i<nums.size(); ++i)
{
if(cnt[i] == ) res[] = i+;
else if(cnt[i]==) res[] = i+;
}
return res;
}
};

solution2:相反数;

参考

1. Leetcode_easy_645. Set Mismatch;

2. Grandyang;

【Leetcode_easy】645. Set Mismatch的更多相关文章

  1. 【LeetCode】645. Set Mismatch 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Hash方法 直接计算 日期 题目地址: https ...

  2. 【Leetcode_easy】1021. Remove Outermost Parentheses

    problem 1021. Remove Outermost Parentheses 参考 1. Leetcode_easy_1021. Remove Outermost Parentheses; 完

  3. 【Leetcode_easy】1022. Sum of Root To Leaf Binary Numbers

    problem 1022. Sum of Root To Leaf Binary Numbers 参考 1. Leetcode_easy_1022. Sum of Root To Leaf Binar ...

  4. 【Leetcode_easy】1025. Divisor Game

    problem 1025. Divisor Game 参考 1. Leetcode_easy_1025. Divisor Game; 完

  5. 【Leetcode_easy】1029. Two City Scheduling

    problem 1029. Two City Scheduling 参考 1. Leetcode_easy_1029. Two City Scheduling; 完

  6. 【Leetcode_easy】1030. Matrix Cells in Distance Order

    problem 1030. Matrix Cells in Distance Order 参考 1. Leetcode_easy_1030. Matrix Cells in Distance Orde ...

  7. 【Leetcode_easy】1033. Moving Stones Until Consecutive

    problem 1033. Moving Stones Until Consecutive 参考 1. Leetcode_easy_1033. Moving Stones Until Consecut ...

  8. 【Leetcode_easy】1037. Valid Boomerang

    problem 1037. Valid Boomerang 参考 1. Leetcode_easy_1037. Valid Boomerang; 完

  9. 【Leetcode_easy】1042. Flower Planting With No Adjacent

    problem 1042. Flower Planting With No Adjacent 参考 1. Leetcode_easy_1042. Flower Planting With No Adj ...

随机推荐

  1. NoClassDefFoundError错误发生的原因

    今上午项目怎么也起不来,总报这个错,上网查一下,大概解释如下:NoClassDefFoundError错误的发生,是因为Java虚拟机在编译时能找到合适的类,而在运行时不能找到合适的类导致的错误.例如 ...

  2. TOMCAT 请求HTTP原理

    一.Tomcat是什么?Tomcat是一个Web应用服务器,同时也是一个Servlet/JSP容器.Tomcat作为Servlet容器,负责处理客户端请求,把请求传送给Servlet,并将Servle ...

  3. .NET Core初览

    .NET Core 初览的应用场景为游戏服务器开发.所以测试在侧重点上更强于IO和密集型计算 网络IO: NetCore:60%CPU QPS 56W C++:31%CPU QPS 58W C++:6 ...

  4. AtCoder NIKKEI Programming Contest 2019 C. Different Strokes (贪心)

    题目链接:https://nikkei2019-qual.contest.atcoder.jp/tasks/nikkei2019_qual_C 题意:给出 n 种食物,Takahashi 吃下获得 a ...

  5. flask实现文件下载功能

    在Flask想要实现文件下载功能,只需要导入 send_from_directory(directory, filename, **options) 然后在视图函数中返回该函数即可 示例代码如下 fr ...

  6. Spring核心概念和案例

    一.Spring概念 1.Spring框架概述 轻量级的Java EE开源框架,它是由Rod Johnson为了解决企业应用程序开发的复杂性而创建, Spring框架提供了一个开发平台,用于整合其他技 ...

  7. MessageDigest的功能及用法

    MessageDigest 类为应用程序提供信息摘要算法的功能,如 MD5 或 SHA 算法.信息摘要是安全的单向哈希函数,它接收任意大小的数据,并输出固定长度的哈希值. MessageDigest ...

  8. icpc 银川 H. Delivery Route SPFA优化

    Problem Description Pony is the boss of a courier company. The company needs to deliver packages to ...

  9. RabbitMQ的5种模式

    队列截图,去rabbitMq.com去找学习文档 =========================================================================== ...

  10. 1059 Prime Factors(25 分)

    Given any positive integer N, you are supposed to find all of its prime factors, and write them in t ...