mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给定一个链表,如果它是有环链表,实现一个算法返回环路的<code>开头节点</code>。若环不存在,请返回 <code>null</code>。</p>
 | 
						||
 | 
						||
<p>如果链表中有某个节点,可以通过连续跟踪 <code>next</code> 指针再次到达,则链表中存在环。 为了表示给定链表中的环,我们使用整数 <code>pos</code> 来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 <code>pos</code> 是 <code>-1</code>,则在该链表中没有环。<strong>注意:<code>pos</code> 不作为参数进行传递</strong>,仅仅是为了标识链表的实际情况。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/07/circularlinkedlist.png" style="height: 97px; width: 300px;" /></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>head = [3,2,0,-4], pos = 1
 | 
						||
<strong>输出:</strong>tail connects to node index 1
 | 
						||
<strong>解释:</strong>链表中有一个环,其尾部连接到第二个节点。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/07/circularlinkedlist_test2.png" style="height: 74px; width: 141px;" /></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>head = [1,2], pos = 0
 | 
						||
<strong>输出:</strong>tail connects to node index 0
 | 
						||
<strong>解释:</strong>链表中有一个环,其尾部连接到第一个节点。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 3:</strong></p>
 | 
						||
 | 
						||
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/07/circularlinkedlist_test3.png" style="height: 45px; width: 45px;" /></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>head = [1], pos = -1
 | 
						||
<strong>输出:</strong>no cycle
 | 
						||
<strong>解释:</strong>链表中没有环。</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>进阶:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li>你是否可以不用额外空间解决此题?</li>
 | 
						||
</ul>
 | 
						||
 | 
						||
<p> </p>
 |