当前位置:网站首页>【LeetCode】 92 整数反转
【LeetCode】 92 整数反转
2020-11-09 23:48:00 【JaneRoad】
题目:


解题思路:
弹出和推入数字 & 溢出前进行检查
https://leetcode-cn.com/problems/reverse-integer/solution/zheng-shu-fan-zhuan-by-leetcode/
代码:
package com.janeroad;
/**
* Created on 2020/11/9.
*
* [@author](https://my.oschina.net/arthor) LJN
*/
public class LC142 {
public static void main(String[] args) {
System.out.println(reverse(1999));
}
public static int reverse(int x) {
int rev = 0;
while (x != 0) {
int pop = x % 10;
x /= 10;
if (rev > Integer.MAX_VALUE/10 || (rev == Integer.MAX_VALUE / 10 && pop > 7)) return 0;
if (rev < Integer.MIN_VALUE/10 || (rev == Integer.MIN_VALUE / 10 && pop < -8)) return 0;
rev = rev * 10 + pop;
}
return rev;
}
}
版权声明
本文为[JaneRoad]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4248053/blog/4710382
边栏推荐
- 京淘项目day10
- mongodb内核源码实现、性能调优、最佳运维实践系列-command命令处理模块源码实现一
- SQL case conversion, remove the space before and after
- Important components of Apache Hadoop
- sql 大小写转换,去掉前后空格
- day84:luffy:优惠活动策略&用户认证&购物车商品的勾选/结算
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- asp.net core中使用Serilog以及自定义Enricher
- 11.9
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
猜你喜欢

做个别人家的网页

C/C++编程笔记:C语言开发坦克大战!纪念我们逝去的小霸王游戏

What is the SRM system? SRM supplier management system functions

公网IP地址和SSL证书可以提升SEO吗?

sql 截取数据中 ‘.’的前后数据

CUDA_存储器模型

【CentOS7操作系统安全加固系列】第(2)篇

Can't find other people's problem to solve

毕业设计之 ---基于微服务框架的电影院订票系统

SQL server attached database access denial resolution summary
随机推荐
剑指offer之打印二叉搜索树中第k小的结点
LeetCode 50 Pow(x,n)
Modify the files in the jar package
Apache Hadoop的重要组成
Brief analysis of LinkedList source code
CRM系统能帮助企业做哪些事?
Dongge ate grapes when he ate an algorithm problem!
C/C++编程日记:逻辑井字棋(圈叉)游戏开发
ES6、ES7、ES8学习指南
CUDA_ constant memory
CUDA_共享内存、访存机制、访问优化
毕业设计之 ---基于微服务框架的电影院订票系统
[QT] subclass QObject + movetothread to realize multithreading
LeetCode 49 字母异位词分组
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
CUDA_常量内存
CUDA_存储器模型
LeetCode 50 Pow(x,n)
如何k个一组反转链表
Analysis steps of commodity background management