You are given an integer array nums of length n. It was meant to contain every value from 1 to n exactly once, but one value got overwritten by a copy of another value. As a result, exactly one value from 1 to n appears twice in nums, and exactly one value from 1 to n does not appear at all.
Return an array [duplicated, missing] where duplicated is the value that appears twice and missing is the value that does not appear.
Examples
Example 1
Input: nums = [1,2,2,4]
Output: [2,3]
Explanation: The value 2 appears twice and the value 3, which should be in a length-4 array of 1..4, does not appear.
Example 2
Input: nums = [1,1]
Output: [1,2]
Explanation: The value 1 appears twice and the value 2, which should be in a length-2 array of 1..2, does not appear.
Constraints
2≤nums.length≤104
1≤nums[i]≤104
Exactly one value from 1 to nums.length appears twice in nums, and exactly one value from 1 to nums.length does not appear.
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up