MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/medium/_0029/Solution.java:11–35  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2018/01/31 desc :

Source from the content-addressed store, hash-verified

9 * </pre>
10 */
11public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected