当前位置:网站首页>【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
边栏推荐
- 快来学习!个性化推荐系统开发指南(附网盘链接)
- Nodejs: handwritten koa Middleware
- November 09, 2020: talk about the similarities and differences between the bulon filter and the cuckoo filter?
- 代码中的软件工程--对menu项目的源码分析
- C / C + + Programming Notes: C language development tank war! In memory of our lost little overlord game
- Formal class D25
- 探访2020 PG技术大会
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- CRM系统能帮助企业做哪些事?
- 嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:王健
猜你喜欢
Do you know your server? Do you know what's inside the server
November 09, 2020: talk about the similarities and differences between the bulon filter and the cuckoo filter?
SQL intercepts the data before and after the '.'
DB engines database ranking in November: PostgreSQL holds the top spot in the same period
So what should investors do with the current market? Now a new investment outlet is coming!
价值超10亿美元的直播系统架构图是什么样子的?
Make a home page
必看!RDS 数据库入门一本通(附网盘链接)
C/C++编程日记:逻辑井字棋(圈叉)游戏开发
SQL filter query duplicate columns
随机推荐
LeetCode 50 Pow(x,n)
The kth smallest node in the print binary search tree of offer
Modify the files in the jar package
sql 筛选查询重复列
Kubernetes-18: installation and use of dashboard
Can public IP address and SSL certificate improve SEO?
代码中的软件工程--对menu项目的源码分析
没有磁盘空间 No space left on device
SRM系统是什么系统?SRM供应商管理系统功能
爱康国宾怒斥国信证券报告失实,已发律师函
表单验证,为避免全局污染,少定义全局变量写法
nodejs篇-手写koa中间件
商品后台管理实现分析步骤
Technical point 5: XML language
C/C++编程日记:逻辑井字棋(圈叉)游戏开发
How to upload your avatar with code and add your own copyright information?
Open source project, private tool, rapid development
CUDA_ Register and local memory
【CentOS7操作系统安全加固系列】第(2)篇
Python提示AttributeError 或者DeprecationWarning: This module was deprecated解决方法