关于visiting医生的费用问题请教# Living
h*t
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
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