当前位置:网站首页>【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
边栏推荐
猜你喜欢

2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...

Error running app:Default Activity not found 解决方法

What is the architecture of a live broadcast system worth more than $1 billion?

Common settings of PLSQL developer

Hengxun Technology: the way to deal with server downtime

在PHP7下怎么大幅度提升Laravel框架性能?安装Stone!

DB-Engines 11月数据库排名:PostgreSQL坐稳同期涨幅榜冠军宝座
![[QT] subclass QObject + movetothread to realize multithreading](/img/47/e91ee9126d495f1b5dea8f016dace2.jpg)
[QT] subclass QObject + movetothread to realize multithreading

Software engineering in code -- source code analysis of menu project

SSL证书和公网IP地址如何影响SEO
随机推荐
DB engines database ranking in November: PostgreSQL holds the top spot in the same period
2020-11-09:谈谈布隆过滤器和布谷鸟过滤器的相同点和不同点?
November 09, 2020: talk about the similarities and differences between the bulon filter and the cuckoo filter?
asp.net Using serilog in core and customizing enrich
CUDA_存储器模型
爱康国宾怒斥国信证券报告失实,已发律师函
会展云技术解读 | 面对突发事故,APP 如何做好崩溃分析与性能监控?
Realization of commodity backstage system
SQL server attached database access denial resolution summary
Fear of reconstruction? I'm too late to tell you how to refactor. Now I'm here
Error running app: default activity not found solution
Gets the property value of a column in the list collection object
Technical point 5: XML language
The movie theater booking system based on micro Service Framework
asp.net core中使用Serilog以及自定义Enricher
What is the architecture of a live broadcast system worth more than $1 billion?
How SSL certificate and public IP address affect SEO
【CentOS7操作系统安全加固系列】第(2)篇
Hengxun Technology: the way to deal with server downtime
eleven point nine