Leetcode7 : Reverse Integer 整数反转问题
2024-08-25 07:39:20
问题描述
Example1: x = 123, return 321
Example2: x = -123, return -321
原题链接: https://leetcode.com/problems/reverse-integer/
解决方案
public int reverse(int x) {
long res = 0; //need to consider the overflow problem
while(x != 0){
res = res * 10 + x % 10; // -11%10 = -1
if(res > Integer.MAX_VALUE || res < Integer.MIN_VALUE){
return 0;
}
x = x/10;
}
return (int)res;
}
最新文章
- 冰冻三尺非一日之寒--web来了
- Android Fragment使用(二) 嵌套Fragments (Nested Fragments) 的使用及常见错误
- 关于使用FusionCharts生成图表时出现invalid xml data错误提示的解决方法
- Tomcat-MAC下添加Tomcat环境并运行
- CSS技巧-rgba函数的妙用
- LightOJ 1094 - Farthest Nodes in a Tree(树的直径)
- 用Unitils测试BaseDao遇到的问题总结
- word-wrap同word-break的区别
- Qt学习
- HDU 1824 Let&#39;s go home
- C#总结(二)事件Event 介绍总结
- 项目中的报错信息,maven报错等的总结
- 重新学习一次javascript;
- BZOJ_2161_布娃娃_权值线段树
- [认证授权] 1.OAuth2授权
- hadoop tez 结合搭建以及测试异常解决
- powershell脚本:你的文件已经被黑客篡改.ps1
- 小甲鱼Python第七讲课后习题
- javascript接口注释法
- spring-boot(hello world)