专栏名称: 每日一道算法题
学习算法是一种信仰,每天都需要坚持!
目录
相关文章推荐
九章算法  ·  某大厂开始“捡漏”L5+码农了 ·  5 天前  
九章算法  ·  一年被裁两次,一个底层码农的大落大起 ·  6 天前  
九章算法  ·  码农又一大“敛财”方向,快追! ·  1 周前  
九章算法  ·  “小透明”码农,逆袭了 ·  1 周前  
九章算法  ·  亚麻实行打卡制!迟到5天视为严重违纪! ·  6 天前  
51好读  ›  专栏  ›  每日一道算法题

[每日一题]645. Set Mismatch

每日一道算法题  · 公众号  · 算法  · 2017-10-22 20:52

正文

题目信息


645. Set Mismatch


The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another number in the set, which results in repetition of one number and loss of another number.


Given an array nums representing the data status of this set after the error. Your task is to firstly find the number occurs twice and then find the number that is missing. Return them in the form of an array.


Example 1:

Input: nums = [1,2,2,4]

Output: [2,3]

Note:

The given array size will in the range [2, 10000].

The given array’s numbers won’t have any order.


提示:提交代码后,需要用简洁的语言解释一下代码思路~ 谢谢


历史题目和总结见公众号「每日一道算法题」


https://leetcode.com/problems/set-mismatch/description/


解题思路




小傅讲解



[每日一题 - 小傅讲解] 645. Set Mismatch

https://youtu.be/760I9vw7uA0

https://www.bilibili.com/video/av15623654/