7. Reverse Integer
来源:互联网 发布:2017电视选购 知乎 编辑:程序博客网 时间:2024/06/17 23:57
public int reverse(int x) { long res=0; while(x!=0) { res=res*10+x%10; x=x/10; } if (res>Integer.MAX_VALUE||res<Integer.MIN_VALUE) { return 0; } return (int)res; }
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
Have you thought about this?
Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!
If the integer's last digit is 0, what should the output be? ie, cases such as 10, 100.
Did you notice that the reversed integer might overflow? Assume the input is a 32-bit integer, then the reverse of 1000000003 overflows. How should you handle such cases?
For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
Note:
The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows
0 0
- [LeetCode]7.Reverse Integer
- LeetCode 7. Reverse Integer
- LeetCode --- 7. Reverse Integer
- LeetCode 7.Reverse Integer
- [Leetcode] 7. Reverse Integer
- 7.Reverse Integer
- [Leetcode]7.Reverse Integer
- LeetCode 7.Reverse integer
- 7. Reverse Integer
- 7. Reverse Integer
- 7.Reverse Integer
- 7.Reverse Integer
- [LeetCode] 7.Reverse Integer
- 7. Reverse Integer
- 7. Reverse Integer
- 7. Reverse Integer
- 7. Reverse Integer
- 7. Reverse Integer LeetCode
- PAT--1125. Chain the Ropes
- 详解并行逻辑回归
- Android中通过Gson进行json解析
- 一个ASP.NET MVC中ajax调用WebApi返回500 Internal Server Error的调错方法。
- Deep Visual-Semantic Alignments for Generating Image Descriptions摘要
- 7. Reverse Integer
- 微信硬件平台开发--精品博客集
- 关于Asmack聊天框架源码粘贴到项目时报错的解决方法
- linux系统安装mysql数据库(需要在线安装)
- 简单工厂模式
- Codeforces #403 Div.2 B.The Meeting Place Cannot Be Changed
- QML,QT, QT Quick关系
- 编程者的养成
- HRBUST1311-火影忍者之~忍者村