问题描述

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;
}

最新文章

  1. 冰冻三尺非一日之寒--web来了
  2. Android Fragment使用(二) 嵌套Fragments (Nested Fragments) 的使用及常见错误
  3. 关于使用FusionCharts生成图表时出现invalid xml data错误提示的解决方法
  4. Tomcat-MAC下添加Tomcat环境并运行
  5. CSS技巧-rgba函数的妙用
  6. LightOJ 1094 - Farthest Nodes in a Tree(树的直径)
  7. 用Unitils测试BaseDao遇到的问题总结
  8. word-wrap同word-break的区别
  9. Qt学习
  10. HDU 1824 Let&#39;s go home
  11. C#总结(二)事件Event 介绍总结
  12. 项目中的报错信息,maven报错等的总结
  13. 重新学习一次javascript;
  14. BZOJ_2161_布娃娃_权值线段树
  15. [认证授权] 1.OAuth2授权
  16. hadoop tez 结合搭建以及测试异常解决
  17. powershell脚本:你的文件已经被黑客篡改.ps1
  18. 小甲鱼Python第七讲课后习题
  19. javascript接口注释法
  20. spring-boot(hello world)

热门文章

  1. Vue组件通信之非父子组件传值
  2. 09-kubernetes configMap secret
  3. (Nginx+PHP+MySQL)单机+Redis部署
  4. 工作中的开发过程(Javaweb路线,写给刚刚实习或者马上就要工作的朋友)
  5. 纯css实现下雪特效
  6. MVC参数传递
  7. Docker系列-(1) 原理与基本操作
  8. Selenium之单选框操作
  9. nmap扫描进阶、msfconsole攻击入门(网安全实训第二天)
  10. Startup/OWIN框架