Iphone新相机敲响了传统相机的丧钟# PDA - 掌中宝
h*2
1 楼
Given a non-empty array A. Set S[k] is defined as S[k]={A[k], A[A[k]], A[A[A
[k]]], ...}. For example, A={5, 4, 0, 3, 1, 6, 2}. S[2]={0, 5, 6, 2}. Find
out the longest Set size.
int solution(vector &A) {
//write your code in c++11
}
My idea is to DFS find each set and update a max size so far. Is it optimal?
Thanks!
[k]]], ...}. For example, A={5, 4, 0, 3, 1, 6, 2}. S[2]={0, 5, 6, 2}. Find
out the longest Set size.
int solution(vector
//write your code in c++11
}
My idea is to DFS find each set and update a max size so far. Is it optimal?
Thanks!