Skip to content

Latest commit

 

History

History
57 lines (41 loc) · 1013 Bytes

File metadata and controls

57 lines (41 loc) · 1013 Bytes

287. Question 287

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 26, 2024

Last updated : June 26, 2024


Related Topics : N/A

Acceptance Rate : Unknown


Solutions

C

/**
 * Thought process
 * Each value will point to another index, and that
 * to another and another 
 * 
 * We're given values [1, n] inclusive of length n+1 so
 * XORing should be (1^2^...^n) ^ repeatVal
 * 
 */


int findDuplicate(int* nums, int numsSize) {
    int fast = nums[0];
    int slow = nums[0];

    do {
        fast = nums[nums[fast]];
        slow = nums[slow];
    } while (fast != slow);

    slow = nums[0];
    while (slow != fast) {
        slow = nums[slow];
        fast = nums[fast];
    }

    return fast;

}