MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / Solution

Class Solution

FindtheDuplicateNumber.java:1–17  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution
2{
3 public int findDuplicate(int[] nums)
4 {
5 int index=0;
6 for(int i=0;i<nums.length;i++)
7 {
8 index=Math.abs(nums[i])-1;
9 if(nums[index]<0)
10 {
11 return Math.abs(nums[i]);
12 }
13 nums[index]=-nums[index];
14 }
15 return -1;
16 }
17}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected