mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			33 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You are given a string <code>s</code> and an integer <code>k</code>. You can choose one of the first <code>k</code> letters of <code>s</code> and append it at the end of the string.</p>
 | 
						|
 | 
						|
<p>Return <em>the lexicographically smallest string you could have after applying the mentioned step any number of moves</em>.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> s = "cba", k = 1
 | 
						|
<strong>Output:</strong> "acb"
 | 
						|
<strong>Explanation:</strong> 
 | 
						|
In the first move, we move the 1<sup>st</sup> character 'c' to the end, obtaining the string "bac".
 | 
						|
In the second move, we move the 1<sup>st</sup> character 'b' to the end, obtaining the final result "acb".
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> s = "baaca", k = 3
 | 
						|
<strong>Output:</strong> "aaabc"
 | 
						|
<strong>Explanation:</strong> 
 | 
						|
In the first move, we move the 1<sup>st</sup> character 'b' to the end, obtaining the string "aacab".
 | 
						|
In the second move, we move the 3<sup>rd</sup> character 'c' to the end, obtaining the final result "aaabc".
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>1 <= k <= s.length <= 1000</code></li>
 | 
						|
	<li><code>s</code> consist of lowercase English letters.</li>
 | 
						|
</ul>
 |