Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Runtime: 0 ms, faster than 100.00% of Java online submissions for Find the Duplicate Number.
- class Solution {
- public int findDuplicate(int[] nums) {
- int slow, normal, fast;
- slow = normal = fast = 0;
- do { normal = nums[normal]; fast = nums[nums[fast]]; } while (normal != fast);
- do { slow = nums[slow]; normal = nums[normal]; } while (slow != normal);
- return normal;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement