0%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| class Solution: def findDuplicate(self, nums: List[int]) -> int: slow = nums[0] fast = nums[slow] while slow != fast: if fast > len(nums)-1 or slow > len(nums)-1: return "没重复数字" slow = nums[slow] fast = nums[nums[fast]] print("有重复数字,在%d位置"%fast) head1 = nums[0] head2 = nums[fast] while head1 != head2: head1 = nums[head1] head2 = nums[head2] return head1
|