Advertisement
ogv

Untitled

ogv
Nov 26th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  1. // Runtime: 0 ms, faster than 100.00% of Java online submissions for Find the Duplicate Number.
  2. class Solution {
  3.     public int findDuplicate(int[] nums) {
  4.         int slow, normal, fast;
  5.         slow = normal = fast = 0;
  6.                
  7.         do { normal = nums[normal]; fast = nums[nums[fast]]; } while (normal != fast);                              
  8.         do { slow = nums[slow]; normal = nums[normal]; } while (slow != normal);
  9.        
  10.         return normal;
  11.     }
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement