Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Find the Duplicate Number in array of n+1 integers having elements from 1 to n
class Solution { public: int findDuplicate(vector<int>& nums) { int slow=0; int fast=0; while(1) { slow=nums[slow]; fast=nums[nums[fast]]; if(fast==slow) break; } slow=0; while(slow!=fast) { slow=nums[slow]; fast=nums[fast]; } return slow; } };
run
|
edit
|
history
|
help
0
pointer array of functions
Amisha
12hours Clock c++
Microsoft - # of fragments (semi-optimised)
YesToDafT
Visakh
javascript style arrays in c++
Empty C++
Base File.cpp
BinTree