author: Blankj blog : http://blankj.com time : 2018/01/31 desc :
| 9 | * </pre> |
| 10 | */ |
| 11 | public class Solution { |
| 12 | public int divide(int dividend, int divisor) { |
| 13 | if (dividend == Integer.MIN_VALUE && divisor == -1) { |
| 14 | return Integer.MAX_VALUE; |
| 15 | } |
| 16 | long dvd = Math.abs((long) dividend); |
| 17 | long dvr = Math.abs((long) divisor); |
| 18 | int res = 0; |
| 19 | while (dvd >= dvr) { |
| 20 | long temp = dvr, multiple = 1; |
| 21 | while (dvd >= temp << 1) { |
| 22 | temp <<= 1; |
| 23 | multiple <<= 1; |
| 24 | } |
| 25 | dvd -= temp; |
| 26 | res += multiple; |
| 27 | } |
| 28 | return (dividend < 0) ^ (divisor < 0) ? -res : res; |
| 29 | } |
| 30 | |
| 31 | public static void main(String[] args) { |
| 32 | Solution solution = new Solution(); |
| 33 | System.out.println(solution.divide(-2147483648, 1)); |
| 34 | } |
| 35 | } |
nothing calls this directly
no outgoing calls
no test coverage detected