Skip to content

Commit

Permalink
Merge pull request #94 from hellache/master
Browse files Browse the repository at this point in the history
Create Find the Duplicate Number.java
  • Loading branch information
PSNAppz authored Oct 20, 2020
2 parents 3478ed0 + 9c3b827 commit 93ba6bb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Problem Solving/Find the Duplicate Number.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Solution to Find the Duplicate Number at LeetCode in Java
*
* author: hellache
* ref: https://leetcode.com/problems/find-the-duplicate-number/
*/
class Solution {
public int findDuplicate(int[] nums) {
int p1=nums[0];
int p2=nums[0];
p1=nums[p1];
p2=nums[nums[p2]];
while(p1!=p2){
p1=nums[p1];
p2=nums[nums[p2]];
}
p1=nums[0];
while(p1!=p2){
p1=nums[p1];
p2=nums[p2];
}
return p1;
}
}

0 comments on commit 93ba6bb

Please sign in to comment.