Divide Two Integers
来源:互联网 发布:淘宝商品删除 重新上架 编辑:程序博客网 时间:2024/06/14 19:18
题目
Divide two integers without using multiplication, division and mod operator.
方法
将除数倍加,直到大于被除数。public int divide(int dividend, int divisor) { int flag = 0; if((dividend < 0 && divisor > 0) || (dividend > 0 && divisor < 0)){ flag = 1; } long divid = Math.abs((long)dividend); long divis = Math.abs((long)divisor); long n; int quotient = 0; int quo = 0; while(divid >= divis){ n = divis; quo = 1; while(n + n <= divid){ n = n + n; quo = quo + quo; } divid =divid - n; quotient += quo; } if(flag == 1){ return -quotient; } return quotient; }
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
- Enter键登陆
- Installing webrtc2sip on Ubuntu 12.04
- 11万奖金的诱惑:三星Galaxy S5终被ROOT
- MySQL存储过程的学习(二)
- 网络问题
- Divide Two Integers
- 常用Maven命令
- STL之队列的运用
- Android加载大图避免程序OOM
- 诊断 Grid Infrastructure 启动问题 (文档 ID 1623340.1)
- Javascript中的对象和原型(一)
- 提取网页中的源代码,以html格式存储
- CityEngine下如何更好的实现影像与地形叠加
- ASP.NET中Onclick和OnserverClick事件的区别