Lintcode反转整数
来源:互联网 发布:网络少年图片 编辑:程序博客网 时间:2024/05/24 04:07
反转整数
将一个整数中的数字进行颠倒,当颠倒后的整数溢出时,返回 0 (标记为 32 位整数)。
样例给定 x = 123
,返回 321
给定 x = -123
,返回 -321
将一个整数中的数字进行颠倒,当颠倒后的整数溢出时,返回 0 (标记为 32 位整数)。
样例
给定 x = 123
,返回 321
给定 x = -123
,返回 -321
public class Solution {
/*
* @param n: the integer to be reversed
* @return: the reversed integer
*/
public int reverseInteger(int n) {
// write your code here
if(n==0){
return 0;
}
long temp=0;
while(n!=0){
temp=temp*10+n%10;
n=n/10;
}
if(temp<Math.pow(-2,31)||temp>Math.pow(2,31)-1){//判断是否越界
return 0;
}
return (int)temp;
}
}
阅读全文
0 0
- lintcode ----反转整数
- lintcode,反转整数
- Lintcode 反转整数
- LintCode - 413.反转整数
- LintCode之反转整数
- 【LintCode】反转整数
- lintcode反转整数
- Lintcode反转整数
- [LintCode]413.反转整数
- 反转整数-LintCode
- [Lintcode] #413 反转整数
- LintCode 第413题 反转整数 【整数】
- LintCode python 小白-简单题-413-反转整数
- 反转整数
- 反转整数
- 反转整数
- 整数反转
- 反转整数
- Java语言基础组成(上)
- cadence 16.6 allegro PCB Editor快捷键调整格点大小
- LeetCode#74 Search a 2D Matrix(week4)
- 栈(一)利用栈计算表达式
- Tomcat(二) Tomcat实现: Servlet与web.xml介绍 以及 源码分析Tomcat实现细节
- Lintcode反转整数
- skynet底层源码阅读(6)-定时器
- 商品sku,N规格js实现
- 使用Apriori算法进行关联分析
- css之position:relitive和top的关系
- python SyntaxError: Non-ASCII character '\xe5' in file的解决方法
- 机器学习分类:监督学习、无监督学习、半监督学习、强化学习
- 欢迎使用CSDN-markdown编辑器
- MyBatis源码研究之$和#