Python | Leetcode Python题解之第7题整数反转

题目:

题解:

def reverse_better(
        self, 
        x: int) -> int:
       
        
        y, res = abs(x), 0
        # 则其数值范围为 [−2^31,  2^31 − 1]
        boundry = (1<<31) -1 if x>0 else 1<<31
        while y != 0:
            res = res*10 +y%10
            if res > boundry :
                return 0
            y //=10
        return res if x >0 else -res

相关推荐

  1. 整数算法(leetcode7)

    2024-04-03 10:54:02       31 阅读
  2. 【算法7. 整数

    2024-04-03 10:54:02       47 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-03 10:54:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-03 10:54:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-03 10:54:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-03 10:54:02       20 阅读

热门阅读

  1. 【linux】常用命令及选项含义+ 英文全称大全

    2024-04-03 10:54:02       17 阅读
  2. Python访问mysql与sqlite3数据库

    2024-04-03 10:54:02       18 阅读
  3. Mysql函数

    2024-04-03 10:54:02       17 阅读
  4. Android Studio 通过 WIFI 调试手机 app

    2024-04-03 10:54:02       17 阅读
  5. leetcode2810--故障键盘

    2024-04-03 10:54:02       19 阅读