Skip to content

Latest commit

 

History

History
18 lines (17 loc) · 422 Bytes

645. Set Mismatch.md

File metadata and controls

18 lines (17 loc) · 422 Bytes
class Solution {
public:
    vector<int> findErrorNums(vector<int>& nums) {
        for (int i = 0; i < nums.size(); ++i) {
            while (nums[i] != nums[nums[i] - 1]) {
                swap(nums[i], nums[nums[i] - 1]);
            }
        }
        for (int i = 0; i < nums.size(); ++i) {
            if (nums[i] != i + 1)
                return {nums[i], i + 1};
        }
        return {};
    }
};