clueless coding // TODO: be smarter

LeetCode Reverse Integer: CPP Solution



TL;DR Code Solution


int reverse(int x) {

    long long res = 0;
    while(x) {
        res = res*10 + x%10;
        x /= 10;
    }
    return (res<INT_MIN || res>INT_MAX) ? 0 : res;


}