Can someone find whats wrong with my code? Thanks a lot!


  • 0
    R

    public int reverse(int x) {
    long k=0;
    int m=0;
    List<Integer> list = new ArrayList<>();
    while (x!=0){
    list.add(x%10);
    x=x/10;
    m++;
    }
    for(int i=0; i<m;i++){
    k=k+list.get(i)*(int)(Math.pow(10,m-i-1));
    }
    if( k > Integer.MAX_VALUE || k < Integer.MIN_VALUE)
    return 0;
    return (int) k;
    }
    }


Log in to reply
 

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