Divide Two Integers
来源:互联网 发布:恐怖游轮 知乎 编辑:程序博客网 时间:2024/05/17 02:55
Divide two integers without using multiplication, division and mod operator.
public class Solution { public int divide(int dividend, int divisor) { int sign = 1; if (dividend < 0) { sign *= -1; } if (divisor < 0) { sign *= -1; } long big = Math.abs((long) dividend); long small = Math.abs((long) divisor); long temp = small; long midres = 1; while (temp < big) { temp <<= 1; midres <<= 1; } int ret = 0; while (temp >= small) { while (big >= temp) { big -= temp; ret += midres; } temp >>= 1; midres >>= 1; } return ret * sign; }}
0 0
- LeetCode: Divide Two Integers
- [LeetCode]Divide Two Integers
- LeetCode: Divide Two Integers
- [LeetCode] Divide Two Integers
- Divide Two Integers
- Divide Two Integers
- LeetCode28:Divide Two Integers
- [Leetcode] Divide Two Integers
- LeetCode Divide Two Integers
- Divide Two Integers
- 【leetcode】Divide Two Integers
- Divide Two Integers
- Divide Two Integers
- [LeetCode]Divide Two Integers
- Divide Two Integers
- LeetCode-Divide Two Integers
- Divide Two Integers
- 25 - Divide Two Integers
- dd命令使用详解
- jar(jar.exe)工具
- Java配置环境变量
- OpenCV中随机森林的实现与字符识别例子
- tcpcopy使用说明
- Divide Two Integers
- MySQL 通配符学习小结
- LVS+keeplived+nginx+apache搭建高可用、高性能php集群
- Android adb 唤醒屏幕 点亮屏幕
- [Bzoj3524][Poi2014]Couriers
- 内核调试神器SystemTap — 简介与使用(一)
- 微软下一代云环境Web开发框架ASP.NET vNext预览
- CoreGraphics QuartzCore CGContextTranslateCTM 用法
- 随记:我们需要怎样的数学教育?