当前位置:网站首页>【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
边栏推荐
- 那么当下的行情投资者该怎么办呢? 现在新的投资风口来了!
- Hengxun Technology: the way to deal with server downtime
- CUDA_全局内存及访问优化
- sql 筛选查询重复列
- Brief analysis of LinkedList source code
- 毕业即失业?大学生如何分配学习时间比例,拥有完整计算机知识体系?
- ES6、ES7、ES8学习指南
- 商品后台系统优化
- Modify the files in the jar package
- Validation failed for one or more entities. See ‘EntityValidationErrors’解决方法
猜你喜欢

CRM系统能帮助企业做哪些事?

LeetCode-378. 有序矩阵中第K小的元素

SSL证书和公网IP地址如何影响SEO

So what should investors do with the current market? Now a new investment outlet is coming!

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

C/C++编程日记:逻辑井字棋(圈叉)游戏开发

SQL filter query duplicate columns

Important components of Apache Hadoop

win7+vs2015+cuda10.2配置TensorRT7.0

Python提示AttributeError 或者DeprecationWarning: This module was deprecated解决方法
随机推荐
商品后台系统实现
CUDA_共享内存、访存机制、访问优化
CUDA_常量内存
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
mongodb内核源码实现、性能调优、最佳运维实践系列-command命令处理模块源码实现一
Baishan cloud technology is selected as the top 100 Internet enterprises in China in 2020
Hand in hand to teach you to use container service tke cluster audit troubleshooting
asp.net Using serilog in core and customizing enrich
Assign the corresponding key and value in the map to the object
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Python提示AttributeError 或者DeprecationWarning: This module was deprecated解决方法
CUDA_ Register and local memory
函数计算进阶-IP查询工具开发
What can CRM system help enterprises do?
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
爱康国宾怒斥国信证券报告失实,已发律师函
Apache Hadoop的重要组成
eleven point nine
那么当下的行情投资者该怎么办呢? 现在新的投资风口来了!
C/C++编程日记:逻辑井字棋(圈叉)游戏开发