#645
Set Mismatch
pupil · 490 · lc easy +27 · verified · 44.1% accepted · 5,404 likes · top 26%
Description
An integer array nums was supposed to contain each value from 1 to n exactly once, but one number was accidentally duplicated, causing another to go missing. Given nums, identify and return [duplicate, missing].
Example 1:
Input: nums = [1,2,2,4]
Output: [2,3]
Example 2:
Input: nums = [1,1]
Output: [1,2]
Code
1
2
3