<doocs>2165.Smallest Value of the Rearranged Number_1.py
def smallestNumber( num: int) -> int:
    if num == 0:
        return 0
    cnt = [0] * 10
    neg = num < 0
    num = abs(num)
    while num:
        num, v = divmod(num, 10)
        cnt[v] += 1
    ans = ""
    if neg:
        for i in range(9, -1, -1):
            if cnt[i]:
                ans += str(i) * cnt[i]
        return -int(ans)
    if cnt[0]:
        for i in range(1, 10):
            if cnt[i]:
                ans += str(i)
                cnt[i] -= 1
                break
    for i in range(10):
        if cnt[i]:
            ans += str(i) * cnt[i]
    return int(ans)
def sample_funcname ( var_0 : int ) -> int :
    if var_0 == 0 :
        return 0
    var_4 = [ 0 ] * 10
    var_5 = var_0 < 0
    var_0 = abs ( var_0 )
    while var_0 :
        var_0 , var_8 = divmod ( var_0 , 10 )
        var_4 [ var_8 ] += 1
    var_11 = ""
    if var_5 :
        for var_14 in range ( 9 , - 1 , - 1 ) :
            if var_4 [ var_14 ] :
                var_11 += str ( var_14 ) * var_4 [ var_14 ]
        return - int ( var_11 )
    if var_4 [ 0 ] :
        for var_14 in range ( 1 , 10 ) :
            if var_4 [ var_14 ] :
                var_11 += str ( var_14 )
                var_4 [ var_14 ] -= 1
                break
    for var_14 in range ( 10 ) :
        if var_4 [ var_14 ] :
            var_11 += str ( var_14 ) * var_4 [ var_14 ]
    return int ( var_11 )
