Untitled
Anonymous
plain_text
01/24/2024 5:05 AM
552 B
20
Indexable
class Solution {
public:
int findDuplicate(vector<int>& nums) {
int fast=0,slow=0;
while(1){
slow=nums[slow];
fast=nums[nums[fast]];
if(slow==fast) break;
}
int slow1=0;
int slow2=slow;
while(slow1!=slow2){
slow1=nums[slow1];
slow2=nums[slow2];
}
return slow1;
}
};Editor is loading...
Leave a Comment