GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — LeetCode/L029_Divide_Two_Integers.java at master · likevson/LeetCode Expand file tree/ Copy pathL029_Divide_Two_Integers.javaMore file actions 49 lines (37 loc) · 818 Bytes / Copy pathL029_Divide_Two_Integers.javaFile metadata and controls49 lines (37 loc) · 818 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 package LeetCode; public class L029_Divide_Two_Integers { public int divide(int dividend, int divisor) { if (divisor == 0) { return Integer.MAX_VALUE; } int result = 0; if (dividend == Integer.MIN_VALUE) { result = 1; if (divisor == -1) { return Integer.MAX_VALUE; } dividend += Math.abs(divisor); } if (divisor == Integer.MIN_VALUE) { return result; } boolean isNeg = ((dividend ^ divisor) >>> 31 == 1) ? true : false; dividend = Math.abs(dividend); divisor = Math.abs(divisor); int c = 0; while (divisor <= (dividend >> 1)) { divisor <<= 1; c++; } while (c >= 0) { if (dividend >= divisor) { dividend -= divisor; result += 1 << c; } divisor >>= 1; c--; } System.out.println(result); return isNeg ? -result : result; } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |