存档

文章标签 ‘twitter’

Twitter online 两题

2013年6月15日 7 条评论

---

今天有个群里发了两道twitter online的题目,看了下,练手写一下。

题一:

A zero-indexed array A consisting of N different integers is given. The array contains all integers in the range [0..N−1]. Sets S[K] for 0 ≤ K < N are defined as follows: S[K] = { A[K], A[A[K]], A[A[A[K]]], ... }. Sets S[K] are finite for each K.

Write a function:

class Solution { public int solution(int[] A); }

that, given an array A consisting of N integers, returns the size of the largest set S[K] for this array. The function should return 0 if the array is empty.

阅读全文...