Reverse Integer LeetCode Java
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
public class Solution {
public int reverse(int x) { if(x==Integer.MIN_VALUE) return 0;
long result = 0;
int i = 0; int temp = (x>0)?1:0;
x = Math.abs(x); while(x != 0){
result *= 10;
result += x%10;
x /= 10;
if(result > Integer.MAX_VALUE || result < Integer.MIN_VALUE) return 0;
}
return (temp==1)?(int)result:(int)-result; }
}
Reverse Integer LeetCode Java的更多相关文章
- leetcode第七题Reverse Integer (java)
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, retu ...
- Reverse Integer [LeetCode]
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to ...
- Reverse Integer ---- LeetCode 007
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 Solution ...
- Roman To Integer leetcode java
问题描述: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range fr ...
- LeetCode第[7]题(Java):Reverse Integer 标签:数学
题目:Reverse Integer 难度:Easy 题目内容: Given a 32-bit signed integer, reverse digits of an integer. Note:A ...
- LeetCode 7 Reverse Integer(反转数字)
题目来源:https://leetcode.com/problems/reverse-integer/ Reverse digits of an integer. Example1: x = 123, ...
- LeetCode之Easy篇 ——(7)Reverse Integer
7.Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: Out ...
- LeetCode: Reverse Integer 解题报告
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...
- LeetCode 【2】 Reverse Integer --007
六月箴言 万物之中,希望最美:最美之物,永不凋零.—— 斯蒂芬·金 第二周算法记录 007 -- Reverse Integer (整数反转) 题干英文版: Given a 32-bit signed ...
随机推荐
- BZOJ1298[SCOI2009]骰子的学问
Description Input 第一行为两个整数n, m.第二行有n个整数,为a1,a2, -, an. Output 包含n行,每行m个1~n×m的正整数,各不相同,以空格分开.如果有多解,输出 ...
- 捕获起英文名Edda的灵感来源,我的心愿是程序员这个行业能够男女人数平衡
在腾讯的暑期训练营结识过不少鹅厂的前辈,他们对我的成长提供了很大的帮助,可以说有着知遇之恩,大部分现在还保持着联系,请教问题时会不吝赐教,以至于就在前两天11号企鹅18岁的成年礼,朋友圈刷满了领腾讯总 ...
- 【MySQL】函数IFNULL、设置默认时间
MySql 函数 IFNUll用法说明 IFNULL(expr1,expr2) 如果 expr1 不是 NULL,IFNULL() 返回 expr1,否则它返回 expr2. IFNULL()返回一个 ...
- Objective-c快速入门
对象(Class)的声明和定义 和其他的语言不同,OC的对象创建分为两个部分.声明部分(@interface)和实现部分(@implementation),且它们都必须使用@end结束. 对象的声明( ...
- mtk flash tool,Win7 On VirtualBox
SP_Flash_Tool_exe_Windows_v5.1624.00.000 Win7 在 VirtualBox, 安裝 mtk flash tool, v5.1628 在燒錄時會 fail. v ...
- Mysql操作语句
MySQL中定义数据字段的类型对你数据库的优化是非常重要的. MySQL支持多种类型,大致可以分为三类:数值.日期/时间和字符串(字符)类型. 数值类型 MySQL支持所有标准SQL数值数据类型. 这 ...
- webpack构建vue项目(再谈配置)
webpack配置起来确实麻烦,这不,之前用刚配好了vue1+的版本,结果在(部分)安卓机上测试,发现存在开启热加载(dev-server)的情况下不能识别vue语法的问题,试了很多方法,都没能很好的 ...
- XMind怎么使用查找功能
XMind思维导图中,XMind搜索功能与XMind查找替换功能乍一看有些相似,然而不尽相同,本文为你着重讲解XMind搜索功能. 首先在XMind思维导图中的工具栏找到"Search&qu ...
- SimpleDateFormat转换时间格式
SimpleDateFormat有两个常用的方法parse和format 其中SimpleDateFormat在创建时有一下集中格式可以选择 SimpleDateFormat sdf = new Si ...
- py-faster-rcnn之从solver文件创建solver对象,建立pythonlayer
faster-rcnn在训练阶段,根据一个solver的prototxt文件创建相应的网络.仅凭一个prototxt就创建网络?其实还涉及到自定义的PythonLayer. 比如lib/rpn/anc ...