mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-06 07:51:41 +08:00
存量题库数据更新
This commit is contained in:
@@ -18,34 +18,32 @@
|
||||
<p>Return <code>true</code><em> if there is a <strong>cycle</strong> in </em><code>nums</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/09/01/img1.jpg" style="width: 402px; height: 289px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,-1,1,2,2]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong>
|
||||
There is a cycle from index 0 -> 2 -> 3 -> 0 -> ...
|
||||
The cycle's length is 3.
|
||||
<strong>Explanation:</strong> The graph shows how the indices are connected. White nodes are jumping forward, while red is jumping backward.
|
||||
We can see the cycle 0 --> 2 --> 3 --> 0 --> ..., and all of its nodes are white (jumping in the same direction).
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/09/01/img2.jpg" style="width: 402px; height: 390px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [-1,2]
|
||||
<strong>Input:</strong> nums = [-1,-2,-3,-4,-5,6]
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong>
|
||||
The sequence from index 1 -> 1 -> 1 -> ... is not a cycle because the sequence's length is 1.
|
||||
By definition the sequence's length must be strictly greater than 1 to be a cycle.
|
||||
<strong>Explanation:</strong> The graph shows how the indices are connected. White nodes are jumping forward, while red is jumping backward.
|
||||
The only cycle is of size 1, so we return false.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/09/01/img3.jpg" style="width: 497px; height: 242px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [-2,1,-1,-2,-2]
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong>
|
||||
The sequence from index 1 -> 2 -> 1 -> ... is not a cycle because nums[1] is positive, but nums[2] is negative.
|
||||
Every nums[seq[j]] must be either all positive or all negative.
|
||||
<strong>Input:</strong> nums = [1,-1,5,1,4]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> The graph shows how the indices are connected. White nodes are jumping forward, while red is jumping backward.
|
||||
We can see the cycle 0 --> 1 --> 0 --> ..., and while it is of size > 1, it has a node jumping forward and a node jumping backward, so <strong>it is not a cycle</strong>.
|
||||
We can see the cycle 3 --> 4 --> 3 --> ..., and all of its nodes are white (jumping in the same direction).
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
Reference in New Issue
Block a user