leetcode 007 Reverse Integer
9. Palindrome Number
Total Accepted: 119423 Total Submissions: 378311 Difficulty: Easy
Determine whether an integer is a palindrome. Do this without extra space.
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 { public int reverse(int x) { long ans=0; //flag 0表示负数,1表示整数 while(x != 0){ ans = ans*10 + x%10; x /= 10; if(ans >= 2147483647 || ans <= -2147483647){ return 0; } } return (int)ans; } }