1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/数组嵌套 [array-nesting].html

28 lines
1.1 KiB
HTML
Raw Normal View History

2022-03-27 20:46:41 +08:00
<p>索引从<code>0</code>开始长度为<code>N</code>的数组<code>A</code>,包含<code>0</code><code>N - 1</code>的所有整数。找到最大的集合<code>S</code>并返回其大小,其中 <code>S[i] = {A[i], A[A[i]], A[A[A[i]]], ... }</code>且遵守以下的规则。</p>
<p>假设选择索引为<code>i</code>的元素<code>A[i]</code><code>S</code>的第一个元素,<code>S</code>的下一个元素应该是<code>A[A[i]]</code>,之后是<code>A[A[A[i]]]...</code> 以此类推,不断添加直到<code>S</code>出现重复的元素。</p>
<p>&nbsp;</p>
<p><strong>示例&nbsp;1:</strong></p>
2023-12-09 18:42:21 +08:00
<pre>
<strong>输入:</strong> A = [5,4,0,3,1,6,2]
2022-03-27 20:46:41 +08:00
<strong>输出:</strong> 4
<strong>解释:</strong>
A[0] = 5, A[1] = 4, A[2] = 0, A[3] = 3, A[4] = 1, A[5] = 6, A[6] = 2.
其中一种最长的 S[K]:
S[0] = {A[0], A[5], A[6], A[2]} = {5, 6, 2, 0}
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
2023-12-09 18:42:21 +08:00
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= nums[i] &lt; nums.length</code></li>
2022-03-27 20:46:41 +08:00
<li><code>A</code>中不含有重复的元素。</li>
2023-12-09 18:42:21 +08:00
</ul>