From 7fda1a9f58cbba5f8ed34bac460a109258035b74 Mon Sep 17 00:00:00 2001 From: Rahul Gupta <59743796+rahul22nrp@users.noreply.github.com> Date: Tue, 25 May 2021 12:30:16 +0530 Subject: [PATCH] Create Find the Duplicate Number --- Find the Duplicate Number | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Find the Duplicate Number diff --git a/Find the Duplicate Number b/Find the Duplicate Number new file mode 100644 index 0000000..0a592c8 --- /dev/null +++ b/Find the Duplicate Number @@ -0,0 +1,14 @@ + int findDuplicate(vector& nums) { + int r1=nums[0];int r2=nums[0]; + do{ + r1=nums[r1]; + r2=nums[nums[r2]]; + }while(r1!=r2); + r1=nums[0]; + while(r1!=r2) + { + r1=nums[r1]; + r2=nums[r2]; + } + return r2; + }