it takes a bit more than that

來源: 2009-05-18 19:55:29 [舊帖] [給我悄悄話] 本文已被閱讀:

there are some issues with your method:

1. starting with a[i] != i, you might find a cycle and go back to i. In this cycle, no element occurred more than once.

2. The problem asks you to find one repeated element. Not every element in a cycle is repeated. Finding the exact "entrance" to a cycle is the tricky part of the problem.

The big idea is correct though, and there is a linear time algorithm. Good luck~