C++ solution(beats 94.74 submissions)


  • 0
    T

    #include <math.h>

    class Solution {
    public:
    int reverse(int x) {
    long long sol=0;
    int max=0x7fffffff;
    int min=0x80000000;
    while (x){
    sol=sol*10+x%10;
    if (sol>max||sol<min){
    sol=0;
    break;
    }
    x=x/10;
    }
    return sol;
    }
    };


Log in to reply
 

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