Untitled
unknown
plain_text
a year ago
414 B
6
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