Question:

Reverse digits of an integer.

Example1: x = 123, return 321
Example2: x = -123, return -321

Algorithm:

一位一位的取,然后乘以10

while循环的条件一定要写>0,因为如果-2147483648 程序就陷入死循环

Submitted Code:

class Solution {
public:int reverse(int x) {long long int temp = x>0?x:-x;long long int num = 0;while(temp>0){num = num*10 + temp%10;temp/=10;}if(num>INT_MAX)return 0;return x>0?num:-num;}
};

Accepted Solutions Runtime Distribution:

leetcode No7. Reverse Integer相关推荐

  1. 【翻转整数考虑溢出】LeetCode 7. Reverse Integer

    LeetCode 7. Reverse Integer Solution1:最笨的方法 class Solution {public:int reverse(int x) {if (!x) retur ...

  2. LeetCode 7 Reverse Integer(反转数字)

    题目来源:https://leetcode.com/problems/reverse-integer/ Reverse digits of an integer. Example1: x = 123, ...

  3. LeetCode - 7. Reverse Integer

    7. Reverse Integer Problem's Link ------------------------------------------------------------------ ...

  4. LeetCode之Reverse Integer

    1.题目 Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 cli ...

  5. LeetCode - 7 - Reverse Integer

    题目 URL:https://leetcode.com/problems/reverse-integer 解法 这个题目是极其简单的,对于数 x,每次对 10 取余保存为结果,之后 x 除以 10,若 ...

  6. LeetCode 7. Reverse Integer

    问题链接 LeetCode 7 题目解析 给定一个32位有符号整数,求其反转数字. 解题思路 如果是简单反转的话,那这道题就太简单了.题目要求判断溢出问题,32位int类型的范围是-214748364 ...

  7. LeetCode——7. Reverse Integer

    一.题目链接:https://leetcode.com/problems/reverse-integer/ 二.题目大意: 给定一个整数,要求反转该整数之后再返回:如果归返回的整数超过了int型整数的 ...

  8. leetcode 7 Reverse Integer

    class Solution { public:int reverse(int x) {int res = 0;while (x != 0) {int t = res * 10 + x % 10;if ...

  9. [LeetCode] Number of 1 Bits Reverse Integer - 整数问题系列

    目录: 1.Number of 1 Bits  - 计算二进制1的个数 [与运算] 2.Contains Duplicate - 是否存在重复数字 [遍历] 3.Reverse Integer - 翻 ...

最新文章

  1. antirecall怎么打开_QQ/微信防撤回工具 — Anti recall
  2. 我是如何在尼日利亚的沃里创立Google Developers Group GDG分会的,并达到了100位成员...
  3. C++关键字const
  4. 水壶问题 算法导论8.4
  5. workbench设置单元坐标系_Workbench菜单选项中英文对照
  6. Go gin内嵌静态资源go-bindata的安装及使用(GVA)
  7. JSP——JSTL语法总结
  8. 平均交付时长减少五天!腾讯TAPD助力企业高效交付!
  9. 监听手指是否离开屏幕android_Flutter事件监听
  10. 作者:邓景文(1982-),女,中国联合网络通信集团有限公司电子商务部工程师...
  11. java简介 ppt 精,TP1java简介.ppt
  12. Swift 提示 error running playground...
  13. python pandas series加速原理_python pandas中对Series数据进行轴向连接的实例
  14. QCC300x学习笔记:自定义一个GATT client
  15. python读取csmar_Python:爬取上市公司公告-Wind-CSMAR
  16. windows批量修改文件权限
  17. ORACLE ERP consolidation流程(二)
  18. 2009年最新虚拟主机提供商排名榜
  19. 在Ubuntu18.04中使用gazebo配合LOAM算法仿真
  20. 大数据必学Java基础(二十六):数组的应用题

热门文章

  1. 基于Android的社交游戏百宝箱App设计与实现
  2. 拉姆达表达式 追加 条件判断 ExpressionFuncT, bool
  3. Shell攻关之运算符
  4. 1790D Matryoshkas
  5. [Kafka] Kafka基本架构
  6. 分享按钮--百度分享
  7. 5分钟理解边缘概率,联合概率,条件概率,随机事件独立,随机事件依赖
  8. 第二讲——识别加密算法
  9. 如何配置域名的 CNAME
  10. ShardingSphere-JDBC使用笔记