当前位置:网站首页>565. 数组嵌套
565. 数组嵌套
2022-07-17 09:53:00 【anieoo】
原题链接:565. 数组嵌套

solution:
将遍历过的元素标记为-1
class Solution {
public:
int arrayNesting(vector<int>& nums) {
int n = nums.size();
int maxl = 0; //返回值
for(int i = 0;i < n;i++) {
if(nums[i] < 0) continue;
int j = i;
int size = 0;
while(nums[j] >= 0) {
int tmp = nums[j];
nums[j] = -1; //遍历过的元素标记为-1
j = tmp;
size++;
}
//更新最大的嵌套长度
maxl = max(maxl, size);
}
return maxl;
}
};边栏推荐
- C language compilation process
- Microservice splitting for stand-alone projects
- Simple case of wechat applet calling API
- es概念模型与基本故障
- 案例分享 | 基于Linkis+DSS构建合合信息一站式数据开发平台
- Google play app store may delete the overview of APP permissions and use a new combination of data security information
- 使用 Golang 正确处理五大互联网注册机构的 IP 数据
- SharePoint access brief notes
- Day 7 Training
- Encapsulation API, request interception, response interception, authentication timeliness
猜你喜欢
![[paper notes] visual detection and capture method based on deep learning](/img/bd/3a204ad3341814cb1ef29b7fc8f324.png)
[paper notes] visual detection and capture method based on deep learning

Resolve the applicationeventmulticast not initialized - call 'refresh' before multicast events exception

LDA classifier

数据湖(二十):Flink兼容Iceberg目前不足和Iceberg与Hudi对比
![[Hongke] lidar safety system: making the world safer](/img/35/23986a66c63d51862c7562834d6a89.png)
[Hongke] lidar safety system: making the world safer

Dynamic memory management

Shell notes

Simple case of wechat applet calling API

Express

Markdown (5): anchor link
随机推荐
C# 读写文本,生成二维码
shell-笔记
Towhee daily model weekly report
Es conceptual model and basic faults
小说里的编程 【连载之十一】元宇宙里月亮弯弯
封装API,request拦截,response拦截,身份验证时效性
05---增透膜
LabVIEW用了多线程,程序是不是会跑的更快些
电脑拨号上网
ETCD数据库源码分析——初始化EtcdServer结构体
L1-088 quiet recommendation (test point 1)
After working hard, I found that there were so many messes around
LDA分类器
如何在docker里搭建自己的云数据库
力扣(LeetCode)197. 上升的温度(2022.07.16)
Resolve the applicationeventmulticast not initialized - call 'refresh' before multicast events exception
Target detection model size calculation, model complexity (parameter conversion formula)
C# - this 的用法
Static routing!! Static routing!! Static routing!!
Qprocess of QT