mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			31 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to find the <strong>maximum</strong> sum of a pair of numbers from <code>nums</code> such that the maximum <strong>digit </strong>in both numbers are equal.</p>
 | 
						|
 | 
						|
<p>Return <em>the maximum sum or</em> <code>-1</code><em> if no such pair exists</em>.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> nums = [51,71,17,24,42]
 | 
						|
<strong>Output:</strong> 88
 | 
						|
<strong>Explanation:</strong> 
 | 
						|
For i = 1 and j = 2, nums[i] and nums[j] have equal maximum digits with a pair sum of 71 + 17 = 88. 
 | 
						|
For i = 3 and j = 4, nums[i] and nums[j] have equal maximum digits with a pair sum of 24 + 42 = 66.
 | 
						|
It can be shown that there are no other pairs with equal maximum digits, so the answer is 88.</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> nums = [1,2,3,4]
 | 
						|
<strong>Output:</strong> -1
 | 
						|
<strong>Explanation:</strong> No pair exists in nums with equal maximum digits.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>2 <= nums.length <= 100</code></li>
 | 
						|
	<li><code>1 <= nums[i] <= 10<sup>4</sup></code></li>
 | 
						|
</ul>
 |