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 ...
随机推荐
- Hangfire入门(任务调度)
一.简介 英文官网:http://hangfire.io/ 开源地址:https://github.com/HangfireIO Hangfire 不依赖于具体的.NET应用类型,包含.NET 和.N ...
- [LeetCode] Integer Replacement 整数替换
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If ...
- [LeetCode] Power of Two 判断2的次方数
Given an integer, write a function to determine if it is a power of two. Hint: Could you solve it in ...
- [LeetCode] Best Time to Buy and Sell Stock III 买股票的最佳时间之三
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- C#进阶系列——WebApi 身份认证解决方案:Basic基础认证
前言:最近,讨论到数据库安全的问题,于是就引出了WebApi服务没有加任何验证的问题.也就是说,任何人只要知道了接口的url,都能够模拟http请求去访问我们的服务接口,从而去增删改查数据库,这后果想 ...
- Cocos2dx 3.12 在AndroidStudio上编译配置
转载请标明出处:http://www.cnblogs.com/studweijun/p/5805576.html SDK,NDK,ANT的配置请看这里http://www.cnblogs.com/st ...
- ie11的DOM管理器报错
IE11 Windows7下F12 DOC资源管理器不能用Exception in window.onload: Error: An error has ocurredJSPlugin.3005--- ...
- C#笔记
关键字: 1.internal 被 internal 修饰的东西只能在本程序集(当前项目)内被使用. 注意事项: 1.解决c#代码引用c/c++代码出现的unsafe code错误警告提示 Unsaf ...
- python基础补漏-05-生成器和装饰器
[1]生成器 很难用简单的语言描述生成器. 生成器:从字面上来理解,就是以某种规则为基础,不断的生成数据的工具 生成器函数: 在函数中如果出现了yield关键字,那么该函数就不再是普通函数,而是生成器 ...
- Ajax在静态页面中向指定url发送json请求获取返回的json数据
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...