offer 03 2021-05-31 19:54

Problem Description

public static int findRepeatNumber(int[] nums) {
    for (int i = 0; i < nums.length; i++) {
        while(nums[i]!=i){
            if (nums[nums[i]] != nums[i]) {
                int temp = nums[i];
                nums[i] = nums[temp];
                nums[temp] = temp;
            } else {
                return nums[i];
            }
        }
    }
    return -1;
}
Runtime Memory
0 ms 46 MB

henryxi leetcode list

EOF