My 4ms C solution


  • 0
    U

    int reverse(int x) {

    int t;
    long rtn = 0;
    int flag = 0;
    

    /* int a = n;
    int count = 0 ;//记录末尾0出现的次数
    while(a % 10 == 0)
    {
    count++;
    a /= 10;
    }
    */
    if(x == 0)
    return 0;
    if(x < 0)
    {
    flag = 1;
    x = ~x + 1;
    }
    while(x)
    {
    t = x % 10;
    rtn = 10 * rtn + t;
    x /= 10;
    }
    if ( rtn > 0x7FFFFFFF || rtn < (-0x7FFFFFFF - 1) ) {
    return 0;
    }
    if(flag)
    {
    return -rtn;
    }
    return rtn;
    }


  • 6
    D

    你能调整一下格式吗?
    你能调整一下格式吗?
    你能调整一下格式吗?


  • 0
    C

    oh,my god ,what is this.


  • 0
    D

    well, leetcode has a minimum limit of comment, I just asked if the author could re-edit his program.


  • 1
    L

    can you re-edit your code style?

    it's so hard to understand.

    tks.


Log in to reply
 

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