When testing "1534236469" ,it just overflows.wondering why.my code following


  • -2
    1

    public static int reverse(int b){
    int m=0,d=0;
    long a=0;
    int c=b;
    if(b<0){
    m=-1;
    b=-b;
    System.out.println(b);
    }
    while(b!=0){
    int k=b%10;
    a=(a+k)*10;
    System.out.println("k"+":"+k+" "+"a"+":"+a+" ");
    b=b/10;
    }
    a=a/10;
    System.out.println("a"+":"+a+" ");
    if(m==-1){
    d=-new Long(a).intValue();
    }else{
    d=new Long(a).intValue();
    }
    // d=Integer.parseInt(d);
    return d;
    }


  • 0
    D

    I met the problem too.And I used keyword-long, but it didn't work.


  • 0
    E

    MAX num for Integer: 2^31-1
    if you use Integer.parseInt("9646324351"), it just overflows...and it will throw NumberFormatException.


  • 0
    S
    This post is deleted!

  • 0
    J

    this test case (1534236469 ) has a result(9646324351) bigger than the maximum(2^32 - 1) of type int32, so should the return value be a long type number ???


Log in to reply
 

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