集合 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 (寒光博客)”原创,转载请保留文章出处。
Ordering, Receipting, Rejections, Discounts, and other Purchase Processes ranging Software training institute in laxmi nagar from simple (cash purchase) to advanced (credit card purchase). From the Order to the Receipt (Sales Processes).Orders Received, Delivery, Invoicing, Rejections and Receipting, and POS Invoicing at Retail are all examples of simple (cash sales) to advanced sales processes.
http://biitnewdelhi.com/
If you have no time Use Australia Assignment Help Services for assistance. Writing assignments is difficult, and mostly people find it exhausting. Connect with our assignment helper
https://greatassignmenthelper.com/au/
BIIT is an IT institution for students who want to achieve academic and professional goals. At BIIT, we understand the individual objectives of students and adapt course content according to that. Since its inception we have been recongised Best tally institute in laxmi nagar and our students have consistently shared their experience through their reviews as excellent.
http://biitnewdelhi.com/
Assignment Help from GreatAssignmentHelper.com offer you flawless uae assignment help compositions that assure best grades at very moderate and affordable rates. Our Assignment Help UAE has been consistently offering precise and excellent Online Assignment Help within assigned timelines to a great many understudies across the UAE.
https://greatassignmenthelper.com/ae/
CEA Aviation Pilot Training is an important part of learning. Teachers assign pilot training to their students so that they study what they have learned and try some questions or activity to show their understanding of the topic. Commercial Pilot Training in Canada.There are a lot of students who do not like to do Pilot Training.
http://ceaaviation.org/canada.php
TOP EDUCATION
https://www.totalassignmenthelp.com/au/deakin-university
There is an assignment service that also provides assistance with assignment writing services. It is one thing to pen down all your skills and knowledge and another to do it in a printed way. There is a lot of assignment writing especially in the USA but look for the one who can provide you the best quality service, who has experience in this field, who has already written a lot of successful assignments. Also, try to make a consultation call before anyone considers the best assignment writing service.
https://www.allassignmenthelp.com/assignment-writing-service.html
Have you ever questioned if someone can "pay to take my online class?" Or "take my online class?" You are not alone if the answer is 'yes,' because many students are struggling or stuck in an online class. This is a reality now and service providers can provide professionals for your online courses and exam. Online courses can look like an easier option. But such online courses have the pressure to balance academics and professional work. Most people who take online classes often end up missing courses or are late with homework assignments.
https://www.takemyonlineclassesforme.com/
https://www.takemyonlineclassesforme.com/take-my-online-exam.html
https://www.takemyonlineclassesforme.com/take-my-online-english-class.html
https://www.takemyonlineclassesforme.com/pay-someone-to-take-my-statistics-exam.html
Great survey, I'm sure you're getting a great response.
fuck u ****
Amazing website, Love it. Great work done.
Produce a construction to shows your free reference generator assignments logically. This may aid you a full heap of faces around the issue and conjointly typically doesn't set off this space. Even as the niche can presently be time tested instead of being useful for you in the person. Once developing a well-suited draft on the mission, update this, and make certain it's cheap pay to do my homework online and contains everything at your Allassignmenthelp. https://www.allassignmenthelp.com/pay-someone-to-do-my-homework.html
|´・ω・)ノ 偷偷看看
抓~~住 让你偷看!!OωO
Hard times and hard tasks, the assignments, and the throttling deadliness. We all are aware of such stifling occasions from our university days. What many of us didn’t know is that we may get it done by paying a small fee to an Assignment Helpers. I opted for the service of greatassignementhelper.com and I think that you should try it as well.