Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c3ebe7c

Browse files
committed
Added README.md file for Linked List Cycle
1 parent 5095dad commit c3ebe7c

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

‎141-linked-list-cycle/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<h2><a href="https://leetcode.com/problems/linked-list-cycle">Linked List Cycle</a></h2> <img src='https://img.shields.io/badge/Difficulty-Easy-brightgreen' alt='Difficulty: Easy' /><hr><p>Given <code>head</code>, the head of a linked list, determine if the linked list has a cycle in it.</p>
2+
3+
<p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the&nbsp;<code>next</code>&nbsp;pointer. Internally, <code>pos</code>&nbsp;is used to denote the index of the node that&nbsp;tail&#39;s&nbsp;<code>next</code>&nbsp;pointer is connected to.&nbsp;<strong>Note that&nbsp;<code>pos</code>&nbsp;is not passed as a parameter</strong>.</p>
4+
5+
<p>Return&nbsp;<code>true</code><em> if there is a cycle in the linked list</em>. Otherwise, return <code>false</code>.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/07/circularlinkedlist.png" style="width: 300px; height: 97px; margin-top: 8px; margin-bottom: 8px;" />
10+
<pre>
11+
<strong>Input:</strong> head = [3,2,0,-4], pos = 1
12+
<strong>Output:</strong> true
13+
<strong>Explanation:</strong> There is a cycle in the linked list, where the tail connects to the 1st node (0-indexed).
14+
</pre>
15+
16+
<p><strong class="example">Example 2:</strong></p>
17+
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/07/circularlinkedlist_test2.png" style="width: 141px; height: 74px;" />
18+
<pre>
19+
<strong>Input:</strong> head = [1,2], pos = 0
20+
<strong>Output:</strong> true
21+
<strong>Explanation:</strong> There is a cycle in the linked list, where the tail connects to the 0th node.
22+
</pre>
23+
24+
<p><strong class="example">Example 3:</strong></p>
25+
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/07/circularlinkedlist_test3.png" style="width: 45px; height: 45px;" />
26+
<pre>
27+
<strong>Input:</strong> head = [1], pos = -1
28+
<strong>Output:</strong> false
29+
<strong>Explanation:</strong> There is no cycle in the linked list.
30+
</pre>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Constraints:</strong></p>
34+
35+
<ul>
36+
<li>The number of the nodes in the list is in the range <code>[0, 10<sup>4</sup>]</code>.</li>
37+
<li><code>-10<sup>5</sup> &lt;= Node.val &lt;= 10<sup>5</sup></code></li>
38+
<li><code>pos</code> is <code>-1</code> or a <strong>valid index</strong> in the linked-list.</li>
39+
</ul>
40+
41+
<p>&nbsp;</p>
42+
<p><strong>Follow up:</strong> Can you solve it using <code>O(1)</code> (i.e. constant) memory?</p>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /