mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			33 lines
		
	
	
		
			1019 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			1019 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你一个长度为 <code>n</code> 的整数数组 <code>nums</code> ,请你返回 <code>nums</code> 中最 <strong>接近</strong> <code>0</code> 的数字。如果有多个答案,请你返回它们中的 <strong>最大值</strong> 。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre><b>输入:</b>nums = [-4,-2,1,4,8]
 | 
						||
<b>输出:</b>1
 | 
						||
<strong>解释:</strong>
 | 
						||
-4 到 0 的距离为 |-4| = 4 。
 | 
						||
-2 到 0 的距离为 |-2| = 2 。
 | 
						||
1 到 0 的距离为 |1| = 1 。
 | 
						||
4 到 0 的距离为 |4| = 4 。
 | 
						||
8 到 0 的距离为 |8| = 8 。
 | 
						||
所以,数组中距离 0 最近的数字为 1 。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre><b>输入:</b>nums = [2,-1,1]
 | 
						||
<b>输出:</b>1
 | 
						||
<b>解释:</b>1 和 -1 都是距离 0 最近的数字,所以返回较大值 1 。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= n <= 1000</code></li>
 | 
						||
	<li><code>-10<sup>5</sup> <= nums[i] <= 10<sup>5</sup></code></li>
 | 
						||
</ul>
 |