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. Linux环境下安装mysql5.6(二进制包不是rpm格式)

    一.准备: 1.CentOS release 6.8 2.mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz 3.Linux下MySQL5.6与MySQL5.7安装方法 ...

  2. 【CCF CSP】 20171203 行车路线 Java(有问题)80分

    问题描述 小明和小芳出去乡村玩,小明负责开车,小芳来导航. 小芳将可能的道路分为大道和小道.大道比较好走,每走1公里小明会增加1的疲劳度.小道不好走,如果连续走小道,小明的疲劳值会快速增加,连续走s公 ...

  3. 2019-2020-1 20199312《Linux内核原理与分析》第五周作业

    使用库函数API获取当前时间 #include <stdio.h> #include <time.h> int main() { time_tt tt; struct tm * ...

  4. LeetCode 269. Alien Dictionary

    原题链接在这里:https://leetcode.com/problems/alien-dictionary/ 题目: There is a new alien language which uses ...

  5. 原生JS实现滑动验证功能

    一般很多网站都有滑动验证的功能,简单滑动验证的原理如下图所示: 主要理解思想就行 图中的代码可能和实际写的有所不同 HTML和CSS也可根据仔细的喜好就行修改 完整代码: <!DOCTYPE h ...

  6. datax 从mysql到mysql

    需求:把a服务器上mysql数据迁移到b服务器上mysql中. 1.下载datax:  https://github.com/alibaba/DataX 2.解压tar -zxvf datax.tar ...

  7. 1040 too many connections

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

  8. MongoDB 集群设置集合分片生效及查看集合分片情况

    一.设计DB分片与Collection分片 #连接mongos /opt/mongodb/mongodb-linux-x86_64-2.4.8/bin/mongo  127.0.0.1:27017   ...

  9. CF1051D Bicolorings 递推

    考试T2,随便推一推就好了~ code: #include <bits/stdc++.h> #define N 1015 #define mod 998244353 #define ll ...

  10. $.extend和$.fn.extend详解

    一.定义 $.extend()属于j全局的Query对象,用于将一个或多个对象合并到目标对象上: $.fn.extend()属于jQuery的原型对象,用于在jQuery原型上扩展实例属性和方法. 二 ...