当前位置:网站首页>【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
边栏推荐
猜你喜欢
随机推荐
Leetcode 49 letter heterotopic word grouping
爱康国宾怒斥国信证券报告失实,已发律师函
SQL case conversion, remove the space before and after
代码中的软件工程--对menu项目的源码分析
Apache Hadoop的重要组成
Fear of reconstruction? I'm too late to tell you how to refactor. Now I'm here
PL/SQL Developer临时用户和新手的功能指南
CUDA常用概念及注意点
LeetCode-378. 有序矩阵中第K小的元素
动物园[CSP2020]
Algorithm template arrangement (1)
【CentOS7操作系统安全加固系列】第(2)篇
CUDA_ Shared memory, memory access mechanism, access optimization
So what should investors do with the current market? Now a new investment outlet is coming!
How SSL certificate and public IP address affect SEO
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
必看!RDS 数据库入门一本通(附网盘链接)
How to carry out modular power operation efficiently
mongodb内核源码实现、性能调优、最佳运维实践系列-command命令处理模块源码实现一
ERP的权限管理的操作与设计--开源软件诞生24