/*
* @lc app=leetcode id=565 lang=cpp
*
* [565] Array Nesting
*/
// @lc code=start
class Solution {
public:
int arrayNesting(vector<int>& nums) {
int N = nums.size();
vector<int> V(N,0);
int cnt = 0;
int loc = 0;
int ans = 1;
for(int i=0;i<N;i++){
if(V[i] == 0){
cnt = 0;
loc = i;
while(V[loc] == 0 ){
V[loc] = 1;
loc = nums[loc];
cnt ++;
}
ans = max(ans, cnt);
}
}
return ans;
}
};
// @lc code=end
No.258 - LeetCode[565] Array Nesting
最新推荐文章于 2024-07-25 19:34:38 发布