首页 > 其他 > 详细

645. Set Mismatch挑出不匹配的元素和应该真正存在的元素

时间:2018-04-25 22:42:18      阅读:203      评论:0      收藏:0      [点我收藏+]

[抄题]:

he 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]

 [暴力解法]:

hashset

时间分析:

空间分析:n

 [优化后]:

时间分析:

空间分析:1

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

[一句话思路]:

为了优化空间,判断重复性时 直接*(-1

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

  [五分钟肉眼debug的结果]:

[总结]:

[复杂度]:Time complexity: O() Space complexity: O()

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

 [代码风格] :

 

645. Set Mismatch挑出不匹配的元素和应该真正存在的元素

原文:https://www.cnblogs.com/immiao0319/p/8947574.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!