mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			30 lines
		
	
	
		
			985 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			985 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你一个链表的头节点 <code>head</code> 和一个特定值<em> </em><code>x</code> ,请你对链表进行分隔,使得所有 <strong>小于</strong> <code>x</code> 的节点都出现在 <strong>大于或等于</strong> <code>x</code> 的节点之前。</p>
 | 
						||
 | 
						||
<p>你应当 <strong>保留</strong> 两个分区中每个节点的初始相对位置。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/04/partition.jpg" style="width: 662px; height: 222px;" />
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>head = [1,4,3,2,5,2], x = 3
 | 
						||
<strong>输出</strong>:[1,2,2,4,3,5]
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>head = [2,1], x = 2
 | 
						||
<strong>输出</strong>:[1,2]
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li>链表中节点的数目在范围 <code>[0, 200]</code> 内</li>
 | 
						||
	<li><code>-100 <= Node.val <= 100</code></li>
 | 
						||
	<li><code>-200 <= x <= 200</code></li>
 | 
						||
</ul>
 |