题目

数字翻转,即输入123,返回321;输入-123,返回-321。

代码

 1 class Solution {
 2 public:
 3     int reverse(int x) {
 4         int result = 0, sign = 1;
 5         if(x < 0)      //负数转换为正数统一处理
 6         {
 7             x = -x;
 8             sign = -1;
 9         }
10
11         while(x != 0)
12         {
13             result *= 10;
14             result += x % 10;
15             x /= 10;
16         }
17
18         return result * sign;    //返回时记得加上符号
19     }
20 };

转载于:https://www.cnblogs.com/qieerbushejinshikelou/p/3993776.html

LeetCode题解——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 7. Reverse Integer

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

  5. LeetCode之Reverse Integer

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

  6. LeetCode——7. Reverse Integer

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

  7. LeetCode - 7 - Reverse Integer

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

  8. leetcode No7. Reverse Integer

    Question: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -32 ...

  9. leetcode 7 Reverse Integer

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

  10. LeetCode题解 343.Integer Break

    题目:Given a positive integer n, break it into the sum of at least two positive integers and maximize ...

最新文章

  1. 语言相关系数显著性_相关性分析在SPSS中的具体操作,一文读懂相关系数的含义及使用——【杏花开生物医药统计】...
  2. Go 语言编程 — defer 关键字
  3. 线程的CloseHandle和WaitForSingleObject
  4. [mmu/cache]-ARM cache的学习笔记-一篇就够了
  5. 中粮国际对话国际农民丰收节贸易会 谋定国际农贸现代化
  6. mysql最大述_mysql最大字段数量及 varchar类型总结
  7. ftp服务器生成文件,ftp服务器自动生成文件
  8. notebook pip install 只有星号_每日一点,带你入门Python-星号拆包
  9. MyEclipse的代码提示功能
  10. 条码打印机如何打印流水号
  11. matlab 计算图像峰值信噪比,Matlab评价图像质量,峰值信噪比,模糊系数的计算 | 学步园...
  12. 电视android怎么连接手机助手下载,投屏助手app下载 投屏助手(手机投屏到电视) for Android v2.0 安卓版 下载-脚本之家...
  13. idea使用mvn命令打包报错 不可用
  14. python ddos攻击脚本_【分享】Python简易DDos攻击器源码
  15. 中国移动H1S-3光猫破解路由器桥接教程
  16. 怎样写好Flutter代码
  17. 阿里云 mysql参数_阿里云MYSQL数据库怎么修改参数值?
  18. 继承类的多态和实现接口的多态的区别
  19. Typora实现Markdown云笔记——Typora+有道云笔记+PicGo+阿里云OSS
  20. PHP实现获取url地址中一级域名

热门文章

  1. mysql主从同步开启后的iptables的设定问题
  2. Java中interface接口与abstract class抽象类的区别
  3. NHibernate (一) 五部曲
  4. 用R读取Excel的新方法
  5. 正确使用SqlConnection对象,兼谈数据库连接池
  6. yarn-cluster 和yarn-client区别
  7. 突发!Log4j 爆“核弹级”漏洞,Flink、Kafka等至少十多个项目受影响,微博、京东、网易等大厂都发起应急响应...
  8. 面试官:亿级流量架构分布式事务如何实现?我懵了。。
  9. 厉害了,Netty 轻松实现文件上传!
  10. 虎牙面试官:String长度有限制吗?是多少?我:这太...