Any one can help me?Time Limmeted!


  • -1
    E

    public int divide(int dividend, int divisor) {
    int MAX_INT=java.lang.Integer.MAX_VALUE;
    if(divisor==0){
    return MAX_INT;
    }
    if((dividend>=0&&divisor>=0)||(dividend<=0&&divisor<=0)){
    int dend=Math.abs(dividend);
    int disor=Math.abs(divisor);
    int i=1;
    int a=dend-disor;
    if(dend<disor){
    return 0;
    }
    while(a>=disor){
    i++;
    a=a-disor;
    }
    return i;
    }
    if((dividend>0&&divisor<0)||(dividend<0&&divisor>0)){
    int dend=Math.abs(dividend);
    int disor=Math.abs(divisor);
    int i=1;
    int a=dend-disor;
    if(dend<disor){
    return 0;
    }
    while(a>=disor){
    i++;
    a=a-disor;
    }
    return 0-i;
    }
    return MAX_INT;
    }


Log in to reply
 

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