2022-03-27 20:37:52 +08:00
< p > You are given a string < code > num< / code > representing < strong > the digits< / strong > of a very large integer and an integer < code > k< / code > . You are allowed to swap any two adjacent digits of the integer < strong > at most< / strong > < code > k< / code > times.< / p >
< p > Return < em > the minimum integer you can obtain also as a string< / em > .< / p >
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 20:37:52 +08:00
< img alt = "" src = "https://assets.leetcode.com/uploads/2020/06/17/q4_1.jpg" style = "width: 500px; height: 40px;" / >
< pre >
< strong > Input:< / strong > num = " 4321" , k = 4
< strong > Output:< / strong > " 1342"
< strong > Explanation:< / strong > The steps to obtain the minimum integer from 4321 with 4 adjacent swaps are shown.
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2022-03-27 20:37:52 +08:00
< pre >
< strong > Input:< / strong > num = " 100" , k = 1
< strong > Output:< / strong > " 010"
< strong > Explanation:< / strong > It' s ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros.
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 3:< / strong > < / p >
2022-03-27 20:37:52 +08:00
< pre >
< strong > Input:< / strong > num = " 36789" , k = 1000
< strong > Output:< / strong > " 36789"
< strong > Explanation:< / strong > We can keep the number without any swaps.
< / pre >
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
< li > < code > 1 < = num.length < = 3 * 10< sup > 4< / sup > < / code > < / li >
< li > < code > num< / code > consists of only < strong > digits< / strong > and does not contain < strong > leading zeros< / strong > .< / li >
2023-12-09 18:42:21 +08:00
< li > < code > 1 < = k < = 10< sup > 9< / sup > < / code > < / li >
2022-03-27 20:37:52 +08:00
< / ul >