题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/2cc32b88fff94d7e8fd458b8c7b25ec1
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 进制转换 # @param M int整型 给定整数 # @param N int整型 转换到的进制 # @return string字符串 # class Solution: def solve(self , M: int, N: int) -> str: # write code here t = '0123456789ABCDEF' flag = False if M < 0: flag = True M = -M r = '' res = '' while M > 0: r = t[M%N] res += r M = M//N if flag: res += '-' res = res[::-1] return res