标签:poi problems code number while fas tco solution turn
https://leetcode.com/problems/linked-list-cycle-ii/discuss/44777/Concise-JAVA-solution-based-on-slow-fast-pointers
fast slow, 刚开始全部初始化为0,当作起始点
1 class Solution { 2 public int findDuplicate(int[] nums) { 3 if(nums.length <= 1) return -1; 4 int slow = nums[0]; 5 int fast = nums[nums[0]]; 6 while(slow != fast){ 7 slow = nums[slow]; 8 fast = nums[nums[fast]]; 9 } 10 fast = 0; 11 while(fast != slow){ 12 fast = nums[fast]; 13 slow = nums[slow]; 14 } 15 return fast; 16 17 } 18 }
287. Find the Duplicate Number
标签:poi problems code number while fas tco solution turn
原文地址:https://www.cnblogs.com/goPanama/p/9749863.html