算法——Reverse Integer
来源:互联网 发布:关于网络爆红的论文 编辑:程序博客网 时间:2024/06/11 11:26
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
click to show spoilers.
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.
public class Solution { public int reverse(int x) { int a = x;int b = 0;int result = 0;while(a!=0){b = a % 10;a = a / 10;if(result >= 214748365 || result < -214748364){result = 0;}else{result = result*10+b;}} return result; }}
0 0
- 算法——Reverse Integer
- LeetCode算法题——Reverse Integer
- 算法系列——Reverse Integer
- leetcode—Reverse Integer
- 算法系列--Reverse Integer
- Reverse Integer算法
- Reverse Integer算法研究
- Reverse Integer算法题
- LeetCode——Reverse Integer
- LeetCode——Reverse Integer
- LeetCode7——Reverse Integer
- LeetCode——Reverse Integer
- LeetCode——Reverse Integer
- leetcode——Reverse Integer
- <7>——Reverse Integer
- 【leetcode】7—reverse integer
- Reverse Integer(算法分析week5)
- leetcode 007 —— Reverse Integer
- 超简单组织AngularJS模块
- 趣言
- Android配置环境问题
- IE实现图片旋转
- 视频:【LOL撸啊撸】《英雄联盟》Top
- 算法——Reverse Integer
- 跟踪model中属性(值)的变更
- 数字化的企业会带来哪些变革
- 软件开发入门学习的个人看法。
- 轻量级 PHP 框架 TinyLara 更新:更优雅 附中文介绍
- Matlab产生随机数函数rand和randn的“state”和“seed”参数
- win7重装后使用easybcd引导linux
- 果断Mark!国外程序员收集整理的PHP资源大全
- 这是我的 Terminal