【Leetcode_easy】645. Set Mismatch
problem
题意:
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的更多相关文章
- 【LeetCode】645. Set Mismatch 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Hash方法 直接计算 日期 题目地址: https ...
- 【Leetcode_easy】1021. Remove Outermost Parentheses
problem 1021. Remove Outermost Parentheses 参考 1. Leetcode_easy_1021. Remove Outermost Parentheses; 完
- 【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 ...
- 【Leetcode_easy】1025. Divisor Game
problem 1025. Divisor Game 参考 1. Leetcode_easy_1025. Divisor Game; 完
- 【Leetcode_easy】1029. Two City Scheduling
problem 1029. Two City Scheduling 参考 1. Leetcode_easy_1029. Two City Scheduling; 完
- 【Leetcode_easy】1030. Matrix Cells in Distance Order
problem 1030. Matrix Cells in Distance Order 参考 1. Leetcode_easy_1030. Matrix Cells in Distance Orde ...
- 【Leetcode_easy】1033. Moving Stones Until Consecutive
problem 1033. Moving Stones Until Consecutive 参考 1. Leetcode_easy_1033. Moving Stones Until Consecut ...
- 【Leetcode_easy】1037. Valid Boomerang
problem 1037. Valid Boomerang 参考 1. Leetcode_easy_1037. Valid Boomerang; 完
- 【Leetcode_easy】1042. Flower Planting With No Adjacent
problem 1042. Flower Planting With No Adjacent 参考 1. Leetcode_easy_1042. Flower Planting With No Adj ...
随机推荐
- vue 监听子组件事件及组件上使用v-model
- socket.gaierror: [Errno 11001] getaddrinfo failed
- Ubuntu 16.04安装Docker-Compose 与 Can't connect to docker from docker-compose
根据别的 网址做一个记录 : https://www.linuxidc.com/Linux/2017-01/139574.htm Linux环境 Ubuntu 16.04(LTS)curl安装安装 ...
- 31、[源码]-AOP原理-AnnotationAwareAspectJAutoProxyCreato机
31.[源码]-AOP原理-AnnotationAwareAspectJAutoProxyCreato机
- eclipse和scala整合,打包配置文件及打包步骤
我写的是maven项目,pom文件为: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=" ...
- 071_关闭 SELinux
#!/bin/bashsed -i '/^SELINUX/s/=.*/=disabled/' /etc/selinux/configsetenforce 0
- 工作流学习之--PHP工作流插件
一.支持的PHP的工作流插件有: 1. TPFlow(thinkphp work flow):是一款开源的ThinkPHP工作流插件,用来解决OA.ERP.CRM.CMS等等办公软件的审核审批的问题. ...
- [Luogu] 选学霸
https://www.luogu.org/problemnew/show/P2170 并查集+DP #include <iostream> #include <cstring> ...
- indexOf的用法
A.indexOf(B)="-1"表示的是不存在 不等于-1就表示存在 http://www.w3school.com.cn/jsref/jsref_indexOf.asp 没有出 ...
- 'internalField' 和'boundaryField'的区别?【翻译】
翻译自:CFD-online 帖子地址:http://www.cfd-online.com/Forums/openfoam/84322-difference-between-internalfield ...