标签:style color os 使用 io java ar for div
题目:Divide two integers without using multiplication, division and mod operator.
public class Solution { public int divide(int dividend, int divisor) { long a = Math.abs((long) dividend); long b = Math.abs((long) divisor); long res = 0; for (int i = 31; i >= 0; i--) { if (a >> i >= b) { res += 1 << i; a -= b << i; } } return (int) (((dividend ^ divisor) >> 31) == 0 ? (res) : (-res)); } }
标签:style color os 使用 io java ar for div
原文地址:http://blog.csdn.net/u013378502/article/details/38964657