Solution in C++ _ Use Do_While to reduce one more line


  • 0
    D
    class Solution {
    public:
        int reverse(int x) {
            long long int revInt=0;
            do{
                revInt=revInt*10+x%10;
            }while(x=x/10); 
            return (revInt>INT_MAX || revInt<INT_MIN)? 0 : (int)revInt; //overflow check and return
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.