Skip to content

Latest commit

 

History

History
23 lines (12 loc) · 733 Bytes

File metadata and controls

23 lines (12 loc) · 733 Bytes

Solution Notes:

解法:

  1. 朴素解法:

利用 math.log() 求出 x 的位数,然后利用 mod 操作依次按位累加得到输出。 注意: math.log() 只能输入正整数;输出越界需要额外判断。

Variationx 的低位到高位处理,每次将 ans *=10 可以避免使用 math.log()

  1. Pythonic 解法:

x_str = str(x) 直接把 x 转化成字符串,然后 ans = x_str[::-1] 得到反转的数字。 注意: 输出越界需要额外判断。

注意:

  1. 输入越界(超出32位整型)的数据需要输出0,而输出越界的数据也需要输出0。

  2. 如果使用数学方法,需要注意 math.log() 不能处理 x<=0 的输入。