题解 | #反转数字#

反转数字

http://www.nowcoder.com/practice/1a3de8b83d12437aa05694b90e02f47a

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param x int整型 
# @return int整型
#
class Solution:
    def reverse(self , x: int) -> int:
        # write code here
        flag = 0
        if x<0:
            flag = -1
        s = str(abs(x))[::-1]
        if flag:
            tep = int('-'+s)
            if tep < -2**31:
                return 0
            return tep
        else:
            tep = int(s)
            if tep > 2**32 - 1:
                return 0
            return tep
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务