mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			29 lines
		
	
	
		
			968 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			968 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给定一个无序的数组 <code>nums</code>,返回 <em>数组在排序之后,相邻元素之间最大的差值</em> 。如果数组元素个数小于 2,则返回 <code>0</code> 。</p>
 | 
						||
 | 
						||
<p>您必须编写一个在「线性时间」内运行并使用「线性额外空间」的算法。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong> nums = [3,6,9,1]
 | 
						||
<strong>输出:</strong> 3
 | 
						||
<strong>解释:</strong> 排序后的数组是 [1,3,6,9]<strong><em>, </em></strong>其中相邻元素 (3,6) 和 (6,9) 之间都存在最大差值 3。</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong> nums = [10]
 | 
						||
<strong>输出:</strong> 0
 | 
						||
<strong>解释:</strong> 数组元素个数小于 2,因此返回 0。</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
 | 
						||
	<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>
 | 
						||
</ul>
 |