设直线的长度为A,圆周长为B。设有两个人从直线的一头(O)开始前进,第一个人的速度是第二个人的两倍。当第二个人到达交点J时,第一个人在圆周上一点X,X到起点的距离满足 X = 2A mod B。第二个人到达Y点时第一个人追上他。易见Y到J和J到X的距离相等,都是 A mod B。这时再假设有第三个人从起点O出发,速度和第二个人相同,则他们同时到达J点。
The complexity of within each while loop is O(n). The while loop could run O(n) times for the x=y condition to be true. So the worst case complexity of this approach is O(n^2).
I think the simplest approach is to just sum up all the numbers in the array and compare it with n*(n-1)/2. The storage for n^2 is 2*log(n). So the storage limit is not the problem, and the complexity is obviously O(n).