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
 

leetCode练题——7. Reverse Integer的更多相关文章

  1. leetcode算法题笔记|Reverse Integer

    /** * @param {number} x * @return {number} */ var reverse = function(x) { var s; if(x<0){ s=-x; } ...

  2. 乘风破浪:LeetCode真题_013_Roman to Integer

    乘风破浪:LeetCode真题_013_Roman to Integer 一.前言 上一节我们讨论了如何把阿拉伯数字转换成罗马数字,现在我们需要思考一下如何把罗马数字转换成阿拉伯数字,其实我们仔细观擦 ...

  3. 乘风破浪:LeetCode真题_008_String to Integer (atoi)

    乘风破浪:LeetCode真题_008_String to Integer (atoi) 一.前言 将整型转换成字符串,或者将字符串转换成整型,是经常出现的,也是必要的,因此我们需要熟练的掌握,当然也 ...

  4. 【算法】LeetCode算法题-Roman To Integer

    这是悦乐书的第145次更新,第147篇原创 今天这道题和罗马数字有关,罗马数字也是可以表示整数的,如"I"表示数字1,"IV"表示数字4,下面这道题目就和罗马数 ...

  5. LeetCode 【2】 Reverse Integer --007

    六月箴言 万物之中,希望最美:最美之物,永不凋零.—— 斯蒂芬·金 第二周算法记录 007 -- Reverse Integer (整数反转) 题干英文版: Given a 32-bit signed ...

  6. LeetCode之“数学”:Reverse Integer && Reverse Bits

    1. Reverse Integer 题目链接 题目要求: Reverse digits of an integer. Example1: x = 123, return 321 Example2:  ...

  7. Leetcode算法题 7. Reverse Integer2

    7. Reverse Integer 题目描述: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Inp ...

  8. Leetcode 题目整理-2 Reverse Integer && String to Integer

    今天的两道题关于基本数据类型的探讨,估计也是要考虑各种情况,要细致学习 7. Reverse Integer Reverse digits of an integer. Example1: x = 1 ...

  9. LeetCode专题-Python实现之第7题:Reverse Integer

    导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...

随机推荐

  1. wpf实现一个windows定时关机的工具

    基本界面 起源 在家睡前喜欢用电脑放情景喜剧看,电脑需要定时关机,一开始直接命令行定时关机,感觉有点小麻烦, 于是最近弄了个有界面的 主要功能 在指定的时间之后执行 关机|休眠|重启 的操作, 支持取 ...

  2. Python环境搭建(win)——Pycharm(破解+汉化)

    Pycharm搭建方法(破解+汉化): 本文以pycharm2019.2为例 写在前面:有能力的朋友,希望大家支持正版. IDE是集成开发环境 “Integrated Development Envi ...

  3. Qt中实现点击一个label,跳转到打开一个浏览器链接

    配置模块 首先需要在.pro配置文件中添加QT += network 重写自定义Label .h文件 class MyClickLabel : public QLabel { Q_OBJECT pub ...

  4. 一文带你看清HTTP所有概念(转)

    一文带你看清HTTP所有概念   上一篇文章我们大致讲解了一下 HTTP 的基本特征和使用,大家反响很不错,那么本篇文章我们就来深究一下 HTTP 的特性.我们接着上篇文章没有说完的 HTTP 标头继 ...

  5. 谷歌浏览器安装jsonview

    1.下载JsonView扩展程序压缩包 下载链接:https://pan.baidu.com/s/1B0IkrHHyTiYtwJEGE_halA 提取码:myi6 2.解压这个压缩包 3.打开谷歌浏览 ...

  6. 巨杉数据库入选年度Gartner Peer Insights报告,获得市场高度评价

    Gartner Peer Insights 年度评选结果于近日出炉,在数据库管理系统市场报告中,巨杉数据库获得了总平均分4.7(满分5分)的成绩,在众多国际厂商中位居第三,是国内唯一一家入选的数据库厂 ...

  7. centos7下使用selenium实现文件上传

    1.pip install SendKeys 2. 利用js去掉元素的隐藏属性,然后输入: 一般控制元素显示或隐藏是用display属性来实现的 style.display = “none”,表示元素 ...

  8. linux网卡

    手动启动 ifup eth0 查询网卡配置信息 vim /etc/udev/rules.d/70-persistent-net.rules 备注:可以修改网卡名称和MAC地址

  9. Java传(2)

    __________________________夜夜都是魂牵梦绕. 题目: 有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月有生一对兔子,假如兔子都不死,问每个月的兔子 ...

  10. open函数 文件设置缓冲

    # 注释 将文件写入硬件设备时,使用系统调用,这类I/O操作一般时间很长 # 为了减少I/O次数操作,文件通常使用缓冲区(有足够的数据才进行系统调用) # 文件缓冲行为分为: # 全缓冲: open函 ...