// Divide two integers without using multiplication, division and mod operator.


public class Solution {
    public int divide(int dividend, int divisor) {
        // assume given divisor will always be non-zero.
        if(dividend == 0){
            return 0;
        }

        boolean isNeg = (dividend > 0 && divisor < 0) || (dividend < 0 && divisor > 0);

        long dvd  = Math.abs((long)dividend);
        long dvs = Math.abs((long)divisor);
        // dividend = Math.abs(dividend);
        // divisor = Math.abs(divisor);
        int step = 0;

        while((dvs << 1) <= dvd){
            dvs <<= 1;
            step++;
        }

        int res = 0;

        while(step >= 0){
            if(dvd >= dvs){
                dvd -= dvs;
                    res += 1 << step;   
            }

            dvs >>= 1;
            step--;
        }
            
        return res; 
    }
}
@@ -356,16 +356,486 @@
  %3E 0);%0A%0A
+%0A        // When divisor == Integer.MIN_VALUE, will cause infinite loop, while?%0A        // the binary representation of Integer.MIN_VALUE is : 100000000000...0%0A        // the abs value of it doesnt chage, which remains: 100000...000%0A        // so when you double the value of it by doing bitwise right shift, it%0A        // will become 000.000, which will cause the decimal value of it to 0,%0A        // so the first while loop will become infite, causing the TLE error.%0A%0A
         
@@ -1354,13 +1354,90 @@
 urn 
-res; 
+isNeg?  neg(res) : res; %0A    %7D%0A%0A    private int neg(int x)%7B%0A        return ~x + 1;
 %0A   

correct integer min value bug in divide two integer