mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You are given an integer <code>n</code>.</p>
 | 
						|
 | 
						|
<p>A number is called <strong>special</strong> if:</p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li>It is a <strong><span data-keyword="palindrome-integer">palindrome</span></strong>.</li>
 | 
						|
	<li>Every digit <code>k</code> in the number appears <strong>exactly</strong> <code>k</code> times.</li>
 | 
						|
</ul>
 | 
						|
 | 
						|
<p>Return the <strong>smallest</strong> special number <strong>strictly </strong>greater than <code>n</code>.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<div class="example-block">
 | 
						|
<p><strong>Input:</strong> <span class="example-io">n = 2</span></p>
 | 
						|
 | 
						|
<p><strong>Output:</strong> <span class="example-io">22</span></p>
 | 
						|
 | 
						|
<p><strong>Explanation:</strong></p>
 | 
						|
 | 
						|
<p>22 is the smallest special number greater than 2, as it is a palindrome and the digit 2 appears exactly 2 times.</p>
 | 
						|
</div>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<div class="example-block">
 | 
						|
<p><strong>Input:</strong> <span class="example-io">n = 33</span></p>
 | 
						|
 | 
						|
<p><strong>Output:</strong> <span class="example-io">212</span></p>
 | 
						|
 | 
						|
<p><strong>Explanation:</strong></p>
 | 
						|
 | 
						|
<p>212 is the smallest special number greater than 33, as it is a palindrome and the digits 1 and 2 appear exactly 1 and 2 times respectively.<br />
 | 
						|
 </p>
 | 
						|
</div>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>0 <= n <= 10<sup>15</sup></code></li>
 | 
						|
</ul>
 |