登录
  • #刷题

MuleSoft OA求解

Teamocara
727
0
Array A含有N个integers,range[0...N-1]。Set S[k], 0 <= K < N as S[K] = {A[K], A[A[K]], A[A[A[K]]],....},

write a function returns the size of the largest set S[K] for this array. return 0 if empty.

ex:

A[0] = 5, A[1] = 4, A[2] = 0, A[3] = 3, A[4] = 1, A[5] = 6, A[6] = 2

return 4 because S[2] equals {0, 5, 6, 2} 4 elements

要求 time O(N), Space O(N)

求助各路大神, 这题要怎么做啊。。。
0条回复
热度排序

发表回复