给定一个整数,牛牛每次可以交换中相邻的两位数。牛牛想将变为一个大于等于的最小整数(无前导零,即初始为时,结果不为)。牛牛想知道他最少交换多少次可以让变为大于等于的最小整数呢。如有,牛牛仅交换一次使得变为大于等于的最小整数。
示例1
输入
2231,2200
输出
1
说明
见题意描述
示例2
输入
2211,1212
输出
3
说明
变化过程如下:
。最少需要交换3次
备注:
,数据保证初始。
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n long长整型 * @param k long长整型 * @return int整型 */ public int minSwap (long n, long k) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n long长整型 * @param k long长整型 * @return int整型 */ int minSwap(long long n, long long k) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n long长整型 # @param k long长整型 # @return int整型 # class Solution: def minSwap(self , n , k ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n long长整型 * @param k long长整型 * @return int整型 */ public int minSwap (long n, long k) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n long长整型 * @param k long长整型 * @return int整型 */ function minSwap( n , k ) { // write code here } module.exports = { minSwap : minSwap };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n long长整型 # @param k long长整型 # @return int整型 # class Solution: def minSwap(self , n , k ): # write code here
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n long长整型 * @param k long长整型 * @return int整型 */ func minSwap( n int64 , k int64 ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n long长整型 * @param k long长整型 * @return int整型 */ int minSwap(long long n, long long k ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n long长整型 # @param k long长整型 # @return int整型 # class Solution def minSwap(n, k) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n long长整型 * @param k long长整型 * @return int整型 */ def minSwap(n: Long,k: Long): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n long长整型 * @param k long长整型 * @return int整型 */ fun minSwap(n: Long,k: Long): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n long长整型 * @param k long长整型 * @return int整型 */ public int minSwap (long n, long k) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n long长整型 * @param k long长整型 * @return int整型 */ export function minSwap(n: number, k: number): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n long长整型 * @param k long长整型 * @return int整型 */ func minSwap ( _ n: Int64, _ k: Int64) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n long长整型 * @param k long长整型 * @return int整型 */ pub fn minSwap(&self, n: i64, k: i64) -> i32 { // write code here } }
2231,2200
1
2211,1212
3