zzndb's world
All things will better soon...let's see...
Number5 AC
一道简单题,记的流水帐

思路值得学习 Description: Reverse digits of an integer.

Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers.

Note: The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows. Code:

class Solution {
public:
    int reverse(int x) {
       long long re = 0;
        while(x) {
            re = re*10 + x%10;
            x /= 10;
        }
        return (re>INT_MAX || re<INT_MIN) ? 0 : re;
    }
};

FullWeb: ThoughtFulPoint:

re = re*10 + x%10;
            x /= 10;

以上


Last modified on 2017-07-21