当前位置:网站首页>[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]所创,转载请带上原文链接,感谢
边栏推荐
猜你喜欢

C / C + + Programming Notes: C language development tank war! In memory of our lost little overlord game

CUDA_共享内存、访存机制、访问优化

恒讯科技浅谈:出现服务器宕机的处理方式

将Map中对应的key和value赋值到对象中

Day84: Luffy: preferential activity strategy & User Authentication & checking / settlement of shopping cart goods

Fear of reconstruction? I'm too late to tell you how to refactor. Now I'm here

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

11.9

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

Application of V7 version of lvgl Library
随机推荐
CUDA_ constant memory
必看!RDS 数据库入门一本通(附网盘链接)
Fear of reconstruction? I'm too late to tell you how to refactor. Now I'm here
asp.net core中使用Serilog以及自定义Enricher
表单验证,为避免全局污染,少定义全局变量写法
【CentOS7操作系统安全加固系列】第(2)篇
eleven point nine
Assign the corresponding key and value in the map to the object
Come and learn! Development Guide for personalized recommendation system (with internet disk link)
Analysis steps of commodity background management
How to implement LRU algorithm
Leetcode 49 letter heterotopic word grouping
CUDA_存储器模型
快来学习!个性化推荐系统开发指南(附网盘链接)
价值超10亿美元的直播系统架构图是什么样子的?
做个别人家的网页
CUDA_共享内存、访存机制、访问优化
ES6、ES7、ES8学习指南
Validation failed for one or more entities. See ‘EntityValidationErrors’解决方法
Software engineering in code -- source code analysis of menu project