My 8MS 13 lines C++ solution


  • 0
    L

    class Solution {
    public:
    int reverse(int x)
    {
    int sign=x>>31;
    int ret=0;
    int lastBit=x%10;
    int bCnt=0;
    while(x)
    {
    ret = ret*10+x%10;
    x = x/10;
    bCnt++;
    if((bCnt>=10)&&(lastBit>=3)) return 0;
    }
    if(bCnt>=10)
    if((ret>>31)!=sign)return 0;
    return ret;
    }
    };


Log in to reply
 

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