Find the Duplicate Number
Given an array nums containing n+ 1 integers where each integer is between 1 and n(inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.
Example
Example 1:
Example 2:
Note
是Set Mismatch的变种,不能改变数组
使用龟兔赛跑的快慢法吧,实在想不到。。
找入口,一个指向数组起点,一个指向乌龟指针,一起走直到相遇
Code
Last updated