LeetCode #287

Find the Duplicate Number

1개의 풀이 · C++

문제 원문 보기 ↗

SOLUTION INFO

C++ · main.cpp

main.cpp
class Solution {
public:
    int findDuplicate(vector<int>& nums) {
        int slow, fast; slow = fast = nums[0];
        do { slow = nums[slow], fast = nums[nums[fast]]; } while(slow != fast);
        slow = nums[0];
        while(slow != fast) slow = nums[slow], fast = nums[fast];
        return slow;
    }
};
int init = [] {
    ios_base::sync_with_stdio(false);  cin.tie(nullptr);
    return 0;
}();

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.