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. Composer的安装以及替换为国内镜像

    Composer的安装以及使用国内镜像 Composer 学习网址 Composer官网 https://getcomposer.org/ Composer中文网 http://www.phpcomp ...

  2. 进程与线程与GIL的总结

  3. unsafe包的学习和使用

    Go语言之unsafe包介绍及使用 unsafe内容介绍 type ArbitraryType int type Pointer *ArbitraryType func Sizeof(x Arbitr ...

  4. Centos命令和Shell脚本问题集合

    1.cat 错误写法 cat >> somefile.txt << EOF something EOF 原因:EOF 之后一定要是 ENTER(回车) 不能是空格或者其他.EO ...

  5. 【Winfrom-无边框窗体】Winform如何拖动无边框窗体?

    去掉边框 this.FormBorderStyle = FormBorderStyle.None; 方法一: Point mouseOff;//鼠标移动位置变量 bool leftFlag;//标签是 ...

  6. boost::swap

    boost::swap是对标准库里的std::swap的增强和泛化,为交换两个变量的值提供便捷的方法. 为了使用需包含头文件: #include <boost/swap.hpp> 原理 c ...

  7. 1040 too many connections

    先重启mysql. 登录成功后执行以下语句查询当前的最大连接数:select VARIABLE_VALUE from information_schema.GLOBAL_VARIABLES where ...

  8. Educational Codeforces Round 68

    目录 Contest Info Solutions A.Remove a Progression B.Yet Another Crosses Problem C.From S To T D.1-2-K ...

  9. python3 数据类型测试

    type(要测试的数据):

  10. vue日常学习

    1.$refs可以用来进行父子级间通信.ref被用于作为子组件的索引ID,用以方便的在js中直接访问子组件.用法如下parent.$refs.idname 使用方法: 在父级元素上加上ref属性 &l ...