您的位置:首页 > 其它

leetcode 007 Reverse Integer

2016-04-19 19:57 447 查看
Total Accepted:
119423
Total Submissions:
378311
Difficulty: Easy

Determine whether an integer is a palindrome. Do this without extra space.

click to show spoilers.

Subscribe to see which companies asked this question

Have you met this question in a real interview?

package com.archer;
/**
*
* @author Archer
*
* 题意:高位换低位 低位换高位
* 题解: java int 32位  -2147483648----2147483648
*     考虑溢出的问题,可能原数不会溢出,但是转职后会溢出 如测试数据中的1534236469
*/
public class Solution {
publicint reverse(intx) {
longans=0;    //flag 0表示负数,1表示整数

while(x !=0){
ans = ans*10+ x%10;
x /=10;

if(ans >=2147483647 || ans <= -2147483647){
return0;
}
}

return(int)ans;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode