集合 s 包含从 1 到 n 的整数。不幸的是,因为数据错误,导致集合里面某一个数字复制了成了集合里面的另外一个数字的值,导致集合 丢失了一个数字 并且 有一个数字重复 。
给定一个数组 nums 代表了集合 S 发生错误后的结果。
请你找出重复出现的整数,再找到丢失的整数,将它们以数组的形式返回。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/set-mismatch
思路问题
hashmap计数 主要用getordefault方法初始化没有key的初始值(比直接if先判断再初始化方便多了)
水题
class Solution {
public int[] findErrorNums(int[] nums) {
int ans[] = new int[2], result;
HashMap<Integer, Integer> map = new HashMap<>();
for (int num : nums) {
map.put(num, map.getOrDefault(num, 0) + 1);
}
//从1开始到n
for (int num = 1; num < nums.length + 1; num++) {
result = map.getOrDefault(num, 0);
if (result == 2)
ans[0] = num;
else if (result == 0)
ans[1] = num;
}
return ans;
}
}
本文作者:Author: 寒光博客
文章标题:[leetcode] 645. 错误的集合
本文地址:https://dxoca.cn/StudyNotes/394.html 百度已收录
版权说明:若无注明,本文皆为“Dxoca's blog (寒光博客)”原创,转载请保留文章出处。
本文地址:https://dxoca.cn/StudyNotes/394.html 百度已收录
版权说明:若无注明,本文皆为“Dxoca's blog (寒光博客)”原创,转载请保留文章出处。
NICE BLOG
Nellore Escort Service |
Ongole Escort Service |
Kadapa Escort Service |
Rajahmundry Escort Service |
Guntur Escort Service |
Kurnool Escort Service |
Tirupati Escort Service |
Kakinada Escort Service |
Amravati Escort Service |
Belgaum Escort Service |
Gulbarga Escort Service |
Srirangapatna Escort Service |
Tenali Escort Service |
Nandyal Escort Service |
Srikakulam Escort Service |
Proddatur Escort Service |
Adoni Escort Service |
Hindupur Escort Service |
Tadipatri Escort Service |
Anantapur Escort Service |
Tadepalligudem Escort Service |
Guntakal Escort Service |
Madanapalle Escort Service |
Thanks for sharing a meaningful blog post, I always appreciate such stuff.
Hyderabad Escort Service |
Mangalore Escort Service |
Kolar Escort Service |
Dharwad Escort Service |
Hampi Escort Service |
Tumkur Escort Service |
Bidar Escort Service |
Chitradurga Escort Service |
Davanagere Escort Service |
Udupi Escort Service |
Bellary Escort Service |
Shivamogga Escort Service |
Vijayapura Escort Service |
CEA Aviation is the one of the first-class DGCA Ground classes in delhi in case you are looking for ground instructions then CEA Aviation is the right location for you.CEA Aviation is sharing the all information approximately the dgca ground training and the way to clear dgca floor examination CEA Aviation offer the all information and the training is given by way of the professionally instructor and and you're satisfied the trainer and the lessons the CEA Aviation provide the additionally online and offline each training,and the aviation is certified aviation
CEA Aviation is the one of the first-class <a href="https://www.ceaaviation.org/ground-class.php".>DGCA Ground classes in delhi in case you are looking for ground instructions then CEA Aviation is the right location for you.CEA Aviation is sharing the all information approximately the dgca ground training and the way to clear dgca floor examination CEA Aviation offer the all information and the training is given by way of the professionally instructor and and you're satisfied the trainer and the lessons the CEA Aviation provide the additionally online and offline each training,and the aviation is certified aviation
It’s good to take time when preparing for the IELTS exam. Slow and steady practice is essential at the beginning. Best IELTS Coaching in Delhi. But once test-takers improve it’s important that they condition themselves to take the test under assumed test conditions. Each section of the test is timed, so speed matters. Students should start doing test questions in their own time, then start timing themselves once they get more comfortable doing questions.
TOP EDUCATION
https://www.totalassignmenthelp.com/au/deakin-university
Great survey, I'm sure you're getting a great response.
fuck u ****
Amazing website, Love it. Great work done.
|´・ω・)ノ 偷偷看看
抓~~住 让你偷看!!OωO