1、题目
 
7. Reverse Integer

Given a 32-bit signed integer, reverse digits of an integer.

Example 1:

Input: 123
Output: 321

Example 2:

Input: -123
Output: -321

Example 3:

Input: 120
Output: 21

Note:
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

 
2、我的解法

 # -*- coding: utf-8 -*-
# @Time : 2020/1/26 12:33
# @Author : SmartCat0929
# @Email : 1027699719@qq.com
# @Link : https://github.com/SmartCat0929
# @Site :
# @File : 7. Reverse Integer.py
class Solution:
def reverse(self, x: int) -> int:
if x >= -2147483648 and x <= 2147483647:
if x >= 0:
r = ""
else:
r = "-"
w = abs(x)
y = str(w)
n = len(y)
d = []
for i in (y):
d.append(i)
for j in range(n):
c = d.pop()
r = r + c
v = int(r)
if v >= -2147483648 and v <= 2147483647:
return v
else:
return 0
else:
return 0
 

最新文章

  1. 阅读笔记Multi-task Learning for Stock Selection [NIPS1996]
  2. discuz!安装遇到问题的解决方案
  3. 有关tp里搜索框的实现方法
  4. 【项目】UICollectionViewFlowlayout再一次自定义
  5. 不可不知的C#基础 4. 延迟加载 -- 提高性能
  6. JavaScript之字符串
  7. noj [1479] How many (01背包||DP||DFS)
  8. Python自动化运维之23、Dom
  9. javascript之闭包深入理解(二)
  10. 10 个迅速提升你 Git 水平的提示(转)
  11. pm2部署多个nodejs项目配置教程
  12. [POI2014]KUR-Couriers
  13. vue中的数据监听以及数据交互
  14. CentOS环境下使用GIT基于Nginx的私服搭建全过程
  15. vscode插件解析-BookMark
  16. Office DCOM 组件交互权限设置
  17. Windows下Caffe实现图像分类
  18. 浅谈js抽象工厂模式
  19. Java学习笔记之——常用转义符号
  20. sql server2008 R2打开报错:无法识别的配置节 system.serviceModel解决办法分享

热门文章

  1. set的使用
  2. Python复制指定目录的各个子目录下的同名文件到指定文件夹并重命名
  3. HTML连载63-a标签的伪类选择器
  4. Ehcache缓存框架与 Shiro 框架 出现出现验证错误 &amp;&amp; Tomcat 缓存清除的问题
  5. moveTo 与 moveBy的区别 (转贴)
  6. 10.pandas的替换和部分替换(replace)
  7. Devexpress 18.2.7 破解
  8. echarts 设置默认选中,单选
  9. 什么是nuget?nuget包是如何管理
  10. AcWing 802. 区间和 离散化