#7 LeetCode——Reverse Integer

整数的翻转

java代码如下

public class Solution {
    public int reverse(int x) {
        long res = 0;
        int input = x;
        for(int i = 0; input != 0; i++)
        {
            res = res * 10 + input % 10;
            input = input / 10;
        }
        if(res > 2147483647 || res < -2147483648)
        {
            res = 0;
        }
        return (int)res;
    }
}
点赞