Middle-题目127:29. Divide Two Integers

原创 2016年05月31日 20:22:16

题目原文:
Divide two integers without using multiplication, division and mod operator.

If it is overflow, return MAX_INT.
题目大意:
不用乘法、除法、取模实现两个数的除法,如果溢出则返回MAX_INT(232-1)
题目分析:
直接用a/b水过去的,正确的解法好像是模拟二进制的竖式除法,用位运算和加减解决。
源码:(language:java)

public class Solution {
    public int divide(int dividend, int divisor) {
        return (dividend==-2147483648 && divisor == -1)?Integer.MAX_VALUE:dividend/divisor;
    }
}

成绩:
2ms,beats 75.64%,众数3ms,66.70%
Cmershen的碎碎念:
原则上除法是CPU的底层上用硬件实现的,但可以用高级语言代码去模拟。据论坛中所说,实现除法、乘法、乘方等数值运算的问题在面试中还是比较常见的,有时间整理一下。

版权声明:完整版Leetcode题解请出门左转https://github.com/cmershen1/leetcode/tree/master/docs

相关文章推荐

29. Divide Two Integers

两个整数相除

LeetCode 29 Divide Two Integers (C,C++,Java,Python)

Problem: Divide two integers without using multiplication, division and mod operator. If it ...

leetCode 29.Divide Two Integers (两整数相除) 解题思路和方法

Divide Two Integers  Divide two integers without using multiplication, division and mod operato...

[LeetCode-29] Divide Two Integers(两个整数相除,不用乘除取余算术符)

Divide two integers without using multiplication, division and mod operator.If it is overflow, retur...

LeetCode(29)Divide Two Integers

题目内容 Divide two integers without using multiplication, division and mod operator. 题目分析 最容易的想到的办法,是把...

[LeetCode]29.Divide Two Integers

【题目】 Divide two integers without using multiplication, division and mod operator. If it is overfl...

leetcode:29. Divide Two Integers

描述: Divide two integers without using multiplication, division and mod operator.If it is overflow, r...

29. Divide Two Integers/49. Group Anagrams/96. Unique Binary Search Trees/560. Subarray Sum Equals K

Divide Two Integers Problem Description Implementation29. Divide Two IntegersProblem DescriptionDivi...

LeetCode 29 Divide Two Integers(两个整数相除)(*)

翻译不用乘法、除法、取余操作,将两个数相除。如果它溢出了,返回MAX_INT原文Divide two integers without using multiplication, division a...
  • NoMasp
  • NoMasp
  • 2015-11-17 20:04
  • 3618

LeetCode 29. Divide Two Integers

LeetCode 29. Divide Two Integers C++位运算
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)