leetcode no7 - beyondnlp/nlp GitHub Wiki

https://leetcode.com/problems/reverse-integer/description/

int reverse(int x) {

    int head = 1;
    long int max = ((int)(1 << 31))-1;
    long int min = (1 << 31);
    long long int y=0;
    if( x < 0 ){
        head = -1;
        x *= head;
    }
    while( x ){
        y = y * 10 + x % 10;
        x = x / 10;
    }
    if( min < y && y < max ) return head*y;
    return 0;
}