当前位置:网站首页>[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 边栏推荐
- 虚拟化技术KVM
- 34iptables firewall
- Regular expression gadget series
- Run NPM run dev to run 'NPM audit fix' to fix them, or 'NPM audit' for details
- ERROR! MySQL is not running, but PID file exists
- Process and planned task management
- Review of wireless sensor networks (Bilingual)
- Application of load balancing
- GDB的使用
- ceph(分布式存储)
猜你喜欢
随机推荐
Web services (02) - Web server middleware
IO function of standard C library
Shell (9) function
【无标题】
Domain name analysis and DNS configuration installation
Timestamp conversion Greenwich mean time
Deveco could not resolve com.huawei.ohos:hap:2.4.5.0. error
MySQL installation
MySQL master-slave replication and read-write separation
SSH and NFS services
Dynamic programming (knapsack problem)
(hdu1588) Gauss Fibonacci (sum of matrix fast power + bisection matrix proportional sequence)
29shell function
MySQL中对于事务完整的超详细介绍
Share 29 chrome plug-ins, and there is always one for you
Ubuntu12.10安装Mysql5.5(一)
Installation and basic operation of docker
[untitled]
Removal and addition of reference types in template and generic programming
MySQL common statements









