LeetCode: Reverse Integer 解题报告
Reverse Integer
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
click to show spoilers.

SOLUTION 1:
注意越界后返回0.先用long来计算,然后,把越界的处理掉。
public class Solution {
public int reverse(int x) {
long ret = 0;
while (x != 0) {
ret = ret * 10 + x % 10;
x /= 10;
}
if (ret > Integer.MAX_VALUE || ret < Integer.MIN_VALUE) {
return 0;
}
return (int)ret;
}
}
GITHUB:
https://github.com/yuzhangcmu/LeetCode_algorithm/blob/master/math/Reverse.java
LeetCode: Reverse Integer 解题报告的更多相关文章
- LeetCode: Combination Sum 解题报告
Combination Sum Combination Sum Total Accepted: 25850 Total Submissions: 96391 My Submissions Questi ...
- 【LeetCode】Permutations 解题报告
全排列问题.经常使用的排列生成算法有序数法.字典序法.换位法(Johnson(Johnson-Trotter).轮转法以及Shift cursor cursor* (Gao & Wang)法. ...
- LeetCode - Course Schedule 解题报告
以前从来没有写过解题报告,只是看到大肥羊河delta写过不少.最近想把写博客的节奏给带起来,所以就挑一个比较容易的题目练练手. 原题链接 https://leetcode.com/problems/c ...
- LeetCode: Sort Colors 解题报告
Sort ColorsGiven an array with n objects colored red, white or blue, sort them so that objects of th ...
- 【LeetCode】989. Add to Array-Form of Integer 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数组转整数再转数组 模拟加法 日期 题目地址:htt ...
- 【LeetCode】190. Reverse Bits 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 二进制字符串翻转 位运算 日期 题目地址:https://le ...
- 【LeetCode】1012. Complement of Base 10 Integer 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- LeetCode 13 Roman to Integer 解题报告
题目要求 Roman numerals are represented by seven different symbols: I, V, X, L, C, Dand M. Symbol Value ...
- LeetCode 1012 Complement of Base 10 Integer 解题报告
题目要求 Every non-negative integer N has a binary representation. For example, 5 can be represented as ...
随机推荐
- iOS 对 HTTPS 证书链的验证
HTTPS从最终的数据解析的角度,与HTTP相同.HTTPS将HTTP协议数据包放到SSL/TSL层加密后,在TCP/IP层组成IP数据报去传输,以此保证传输数据的安全:而对于接收端,在SSL/TSL ...
- 对IT技术开发职业生涯的思考
对职业生涯的思考 从刚毕业到目前所在公司,差不多6年了,想想这六年里面,自己的能力和刚毕业比有了很大的提升,但是现在在什么能力上,我不知道,毕竟没有去过别的公司.最近也在思考自己未来,算是比较迷茫阶段 ...
- 10个很棒的学习Android 开发的网站
1. Android Developers 作为一个Android开发者,官网的资料当然不可错过,从设计,培训,指南,文档,都不应该错过,在以后的学习过程中慢慢理解体会. 2. Android Gui ...
- 免费的UI素材准备
UI素材准备 UI也是一个专业性比较强的一个活啊,不过还好我有强大的百度,强大的百度有各种强大的网站,下面介绍一些UI常用的网站1.阿里巴巴矢量图标库 http://www.iconfont.cn/p ...
- RSA加密异常
在利用RSA进行数据加密时,出现如下异常: Exception bytes at com.sun.crypto.provider.RSACipher.a(DashoA13*..) at com.sun ...
- 虚拟化—Docker解决方案
What is Docker? Docker is an open-source project to easily create lightweight, portable, self-suffic ...
- PyCharm黄色波浪线提示: Simplify chained comparison
译过来就是,可简化连锁比较: case 1 if a >= 0 and a <= 9: 1 可简化为: if 0 <= a <= 9: 1 就像我们的数学表达式一样.显然这种情 ...
- stm32定时器主从模式
TIM2作master:TIM3,TIM4作slave 定时器2事件更新被用作触发输出TRGO 从定时器TIM3,TIM4工作在从模式:门控模式 触发选择设为:ITR1,这样TIM2的TRGO就连到了 ...
- Excel列添加单引号
="'"&A2&"'," 对A2列同步添加单引号
- docker-compose教程(安装,使用, 快速入门)
1.Compose介绍Docker Compose是一个用来定义和运行复杂应用的Docker工具.一个使用Docker容器的应用,通常由多个容器组成.使用Docker Compose不再需要使用she ...