h***t 发帖数: 2540 | 1 A zero-indexed array A consisting of N integers is given. We visit the
indexes of the array in the following way. In the first step we visit the
index 0; in every subsequent step we move from the visited index K to the
index:
M=K+A[K]
provided M is within the array bounds. Otherwise, K is the last index
visited.
Write a function: given an array A, returns the number of indexes that
cannot be visited by the described procedure.
需要时间和空间复杂度都是N logN | a********m 发帖数: 15480 | 2 不能直接弄个标志数组然后扫瞄一遍么?而且还能防止循环。 | h***t 发帖数: 2540 | 3 你写个code看看?
【在 a********m 的大作中提到】 : 不能直接弄个标志数组然后扫瞄一遍么?而且还能防止循环。
|
|