当前位置:网站首页>[leetcode] 92 integer inversion
[leetcode] 92 integer inversion
2020-11-09 23:48:00 【JaneRoad】
subject :
Their thinking :
Pop and push numbers & Check before spillage
https://leetcode-cn.com/problems/reverse-integer/solution/zheng-shu-fan-zhuan-by-leetcode/
Code :
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]所创,转载请带上原文链接,感谢
边栏推荐
- How to greatly improve the performance of larravel framework under php7? Install stone!
- Interviewer: what are cache penetration, cache avalanche and cache breakdown?
- Fear of reconstruction? I'm too late to tell you how to refactor. Now I'm here
- 京淘项目day10
- 必看!RDS 数据库入门一本通(附网盘链接)
- Optimization of commodity backstage system
- 日常页码样式问题
- Realization of commodity backstage system
- SQL filter query duplicate columns
- 技术点5:XML语言
猜你喜欢
害怕重构?都怪我太晚和你介绍该如何重构,现在我来了
eleven point nine
CUDA_ Memory model
C / C + + Programming Notes: C language development tank war! In memory of our lost little overlord game
Prometheus安装配置
Validation failed for one or more entities. See 'entityvalidationerrors' solution
将Map中对应的key和value赋值到对象中
毕业即失业?大学生如何分配学习时间比例,拥有完整计算机知识体系?
ERP的权限管理的操作与设计--开源软件诞生24
js label语法跳出多重循环
随机推荐
CUDA_ constant memory
剑指offer之打印超过数组一半的数字
商品后台管理实现分析步骤
Error running app: default activity not found solution
Validation failed for one or more entities. See 'entityvalidationerrors' solution
Gets the property value of a column in the list collection object
CUDA_共享内存、访存机制、访问优化
asp.net core中使用Serilog以及自定义Enricher
Problems of input and button (GAP / unequal height / misalignment) and Solutions
Technical point 5: XML language
How to make a set of K reverse linked lists
做个别人家的网页
DB-Engines 11月数据库排名:PostgreSQL坐稳同期涨幅榜冠军宝座
How to implement LRU algorithm
Functional guide for temporary users and novices of PL / SQL developer
CUDA_存储器模型
What can CRM system help enterprises do?
在PHP7下怎么大幅度提升Laravel框架性能?安装Stone!
Common settings of PLSQL developer
CUDA常用概念及注意点