LeetCode: Divide Two Integers
2013-03-20 21:34
369 查看
很多bug还不清楚。。用了网上答案
class Solution { public: int divide(int dividend, int divisor) { // Start typing your C/C++ solution below // DO NOT write int main() function bool isnegtive = false; int multiply = 0; long long a = dividend; long long b = divisor; if (a < 0) { a = -a; isnegtive = !isnegtive; } if (b < 0) { b = -b; isnegtive = !isnegtive; } while (b << multiply <= a) { multiply++; } int ret = 0; for (int i = multiply-1; i >= 0; i--) { if (b << i <= a) { ret = ret | (1 << i); a -= b << i; } } if (isnegtive) ret = -ret; return ret; } };
相关文章推荐
- [LeetCode] Divide Two Integers
- LeetCode_OJ【29】Divide Two Integers
- Leetcode Divide Two Integers
- Leetcode: Divide Two Integers
- leetcode Divide Two Integers
- Leetcode刷题记——29. Divide Two Integers(整数相除Divide two integers without using multiplication, division)
- 个人记录-LeetCode 29. Divide Two Integers
- leetcode--Divide two integers
- LeetCode-Divide Two Integers-快速除法
- leetcode 29. Divide Two Integers
- LeetCode 29 - Divide Two Integers
- [LeetCode] Divide Two Integers
- 【leetcode刷题笔记】Divide Two Integers
- [LeetCode] Divide Two Integers
- LeetCode 29:Divide Two Integers
- [题解][LeetCode][Divide Two Integers]
- 【leetcode】29. Divide Two Integers
- LeetCode -- Divide Two Integers
- [Leetcode] Divide Two Integers
- 2017-09-17 LeetCode_029 Divide Two Integers