leetcode-剑指03-OK

address

int findRepeatNumber(int* nums, int numsSize){
    int a;
    int findone(int m){
        int n = nums[m];
        nums[m] = -1;
        while((n!=-1)&&(nums[n] != n)){
            m = nums[n];
            nums[n] = n;
            n = m;
        }
        return n;
    }
    for(int i = 0; i< numsSize; i++){
        if(nums[i] != i){
            a = i;
            a = findone(a);
            if(a!=-1)
                return a;
        }
    }
    return -1;
}
posted @ 2021-01-20 08:42  RougeBW  阅读(37)  评论(0编辑  收藏  举报