public int solution2(int[] A) {
		// write your code in Java SE 8
		if (A == null || A.length == 0) {
			return -1;
		}
		int result = 0;
		int[] allLength = new int[A.length];
		for (int i = 0; i < A.length; i++) {
			if (A[i] != -1) {
				int temp = 0;
				int j = i;
				while (A[j] != -1 && A[j] != i) {
					int lastNumber = j;
					j = A[j];
					A[lastNumber] = -1;
					temp++;
				}
				if (A[j] == -1) {
					temp += allLength[j];
				}
				allLength[i] = temp;
				if (temp > result) {
					result = temp;
				}
			}
		}
		return result;
	}