当前位置:网站首页>[daily question] 565. Array nesting
[daily question] 565. Array nesting
2022-07-27 02:02:00 【Wang Liuliu, who loves to write bugs】
565. Array nesting
Input : A = [5,4,0,3,1,6,2]
Output : 4
explain :
A[0] = 5, A[1] = 4, A[2] = 0, A[3] = 3, A[4] = 1, A[5] = 6, A[6] = 2.
One of the longest S[K]:
S[0] = {A[0], A[5], A[6], A[2]} = {5, 6, 2, 0}
The output is length ..
Regular simulation questions
take A[i] And A[A[i]] There is a directed edge between , Because all numbers range in [0,N−1], And not repeated , So there is at least one ring , The essence of the problem is Find the maximum length of all rings .
Directly simulate according to the meaning of the title , Deal with each... From front to back nums[i], And try to from nums[i] Start and traverse the ring in which it is located , In order to prevent some rings from being processed repeatedly , For the currently passed nums[i] Marked as −1, In this way, each number can be accessed no more than 3 Time , The overall complexity is O(n).

class Solution {
public 边栏推荐
- Use ECs and OSS to set up personal network disk
- Shell (13) Three Musketeers
- Shell (6) if judgment
- MySQL master-slave replication and read-write separation
- Harmonyos image processing application development live broadcast notes
- regular expression
- 39 installing LNMP
- Proxmox ve installation and initialization
- Docker高级篇之Mysql主从复制、Redis集群扩容缩容配置案例详解
- The bottom implementation of vector container
猜你喜欢
随机推荐
[untitled]
SSH and NFS services
MySQL multi table query
GDB的使用
PXE experiment
B - Bomb HDU - 5934
24ssh service
22FTP
23nfs shared storage service
RT-thread学习
count(*)为什么很慢
25pxe efficient batch network installation
22FTP
Review of wireless sensor networks (Bilingual)
introduction
RT thread learning
Makefile
Ubuntu12.10 installing mysql5.5 (II)
构造函数,拷贝函数和析构函数的区别
[untitled]









