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. BLOB和TEXT

    区别: BLOB存储的是二进制数据,没有排序规则或字符集. TEXT存储的是字符,有排序规则和字符集. 因为Memory引擎不支持BLOB和TEXT类型,最好的解决方案避免使用BLOB和TEXT类型. ...

  2. Django REST framework+Vue 打造生鲜电商项目(笔记四)

    (PS:部分代码和图片来自博客:http://www.cnblogs.com/derek1184405959/p/8813641.html.有增删) 一.用户登录和手机注册 1.drf的token功能 ...

  3. 使用JSP/Servalet技术开发新闻发布系统------JSP数据交互一

    什么是内置对象 JSP内置对象是 Web 容器创建的一组对象,不用通过手动new就可以使用 JSP中的九大内存对象  request 请求对象  response 响应对象  out   输出对象  ...

  4. javascript权威指南第14章 表单脚本示例代码

    HTML部分 <!DOCTYPE html> <html> <head> <title></title> </head> < ...

  5. Greenplum 表空间和filespace的用法

    转载:https://yq.aliyun.com/articles/190 Greenplum支持表空间,创建表空间时,需要指定filespace.postgres=# \h create table ...

  6. 浅谈"$fake$树"——虚树

    树形$dp$利器——"$fake$"树(虚树$qwq$)  前置知识: $1.$$dfs$序 $2.$倍增法或者树链剖分求$lca$  问题引入: 在许多的树形动规中,很多时候点特 ...

  7. promise 及 setTimeout 执行顺序

    setTimeout(function() { console.log(1); }, 0); new Promise(function(res, rej) { res(2); console.log( ...

  8. uoj #139

    树链剖分//模板题由于存在换根操作对所有关于节点 u 的修改和查询操作进行分类讨论若 Root 在 u 的子树中,则不处理 u 所在的 Root 的那颗子树否则不会有影响寻找 Root 所在的那颗子树 ...

  9. gdb 预备知识

    1.gcc的-g选项 如果要使用gdb进行调试,必须在编译时在gcc中加入-g选项,使用参数 -g 表示将源代码调试信息编译到可执行文件中. #include <stdio.h> int ...

  10. windows使用强大的wget工具

    原文链接:https://www.cnblogs.com/hzdx/p/6432161.html wget下载地址:http://www.interlog.com/~tcharron/wgetwin. ...