Set Mismatch
The setS
originally contains numbers from 1 ton
. 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
Note
在1-N中找重复两次的数,直接在数组上进行state改变,让它变负数,再次遇到重复的数的话,其值就是负数了,直接找到
Code
Last updated