Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int findDuplicate(vector<int>& nums) {
- int slow, fast;
- slow = nums[0]; 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;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement