当前位置:网站首页>【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
边栏推荐
- 代码中的软件工程--对menu项目的源码分析
- What is the architecture of a live broadcast system worth more than $1 billion?
- Algorithm template arrangement (1)
- CUDA_全局内存及访问优化
- 剑指offer之打印二叉搜索树中第k小的结点
- 动物园[CSP2020]
- Aikang Guobin denounced Guoxin Securities report as untrue and sent a lawyer's letter
- How to greatly improve the performance of larravel framework under php7? Install stone!
- LeetCode-378. 有序矩阵中第K小的元素
- 公网IP地址和SSL证书可以提升SEO吗?
猜你喜欢

CUDA_存储器模型

Prometheus安装配置

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

Jingtao project Day10

crm系统的成本一般是多少?

PL/SQL Developer临时用户和新手的功能指南

Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom

Make a home page

商品后台系统优化

CUDA_ Shared memory, memory access mechanism, access optimization
随机推荐
How to upload your avatar with code and add your own copyright information?
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Application of V7 version of lvgl Library
CUDA_ Register and local memory
jt-京淘项目
Function calculation advanced IP query tool development
Realization of commodity backstage system
C + + game development
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
How to carry out modular power operation efficiently
Common concepts and points for attention of CUDA
sql 筛选查询重复列
CUDA_ Shared memory, memory access mechanism, access optimization
PLSQL Developer常用设置
Open source project, private tool, rapid development
CUDA_全局内存及访问优化
【CentOS7操作系统安全加固系列】第(2)篇
Kubernetes-18: installation and use of dashboard
Python prompt attributeerror or depreciation warning: This module was degraded solution
Common settings of PLSQL developer