• leetcode——7.整数反转


    class Solution:
        def reverse(self, x: int) -> int:
            i=1
            if x==0:
                return 0
            while x%(10**i)==0:
                i+=1    
            if x>=0:
                a=list(str(x))
                b=[int(a[i])*10**i for i in range(len(a))]
                if sum(b)>2**31-1:
                    return 0
                return sum(b)
            elif x<0:
                a=abs(x)
                a=list(str(a))
                b=[int(a[i])*10**i for i in range(len(a))]
                if -sum(b)<-2**31:
                    return 0
                return -sum(b)
    执行用时 :44 ms, 在所有 Python3 提交中击败了90.44%的用户
    内存消耗 :13.8 MB, 在所有 Python3 提交中击败了5.21%的用户
     
    执行用时为 20 ms 的范例
    class Solution:
        def reverse(self, x: int) -> int:
            rea=int(str(x)[::-1]) if x>=0 else -int(str(-x)[::-1])
            return rea if rea.bit_length()<32 else 0
    执行用时 :36 ms, 在所有 Python3 提交中击败了99.18%的用户
    内存消耗 :14 MB, 在所有 Python3 提交中击败了5.21%的用户
     
    精巧!!
    return rea if rea.bit_length()<32 else 0
    精巧!!!!
                                                                         ——2019.10.10
     
     
     
     
     
     
    我的前方是万里征途,星辰大海!!
  • 相关阅读:
    linux 系统管理(2) 文件或目录数量统计
    linux系统管理(1)之 内核编译选项查看
    apt 命令大全
    system命令
    ubuntu 登陆闪回
    网络知识之ipset
    mac 系统配置(一)
    windows下的qt编译器配置
    QT5.14.1+qwt-6.1.4编译
    无法打开源文件QtWidgets/QApplication
  • 原文地址:https://www.cnblogs.com/taoyuxin/p/11648730.html
Copyright © 2020-2023  润新知