2 Star 0 Fork 0

ShiboJiang / per_leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
7.整数反转.py 580 Bytes
一键复制 编辑 原始数据 按行查看 历史
Shibo Jiang 提交于 2020-01-04 23:35 . Add #7 new function
#
# @lc app=leetcode.cn id=7 lang=python3
#
# [7] 整数反转
#
# @lc code=start
class Solution:
def reverse(self, x: int) -> int:
tp_rtn = 0
new_int = 0
temp_int = abs(x)
for i in range(len(str(abs(x)))):
pop = temp_int % 10
new_int = new_int*10 + pop
temp_int = temp_int//10
if new_int.bit_length() <= 31:
if x < 0:
tp_rtn = -new_int
else:
tp_rtn = new_int
return tp_rtn
temp = Solution()
print(temp.reverse(-123))
# @lc code=end
1
https://gitee.com/qq353838430/per_leetcode.git
git@gitee.com:qq353838430/per_leetcode.git
qq353838430
per_leetcode
per_leetcode
master

搜索帮助