problem0029

package
v0.0.0-...-899dd15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2020 License: MIT Imports: 1 Imported by: 0

README

29. Divide Two Integers

题目

Divide two integers without using multiplication, division and mod operator.

If it is overflow, return MAX_INT.

解题思路

不能使用乘法,除法和取余运算,编写一个除法函数。大的步骤是

  1. 取出两个数的符号和绝对值
  2. 使用绝对值做除法
  3. 还原结果的符号
  4. 检查是否溢出

其中,使用绝对值做除法是重点,思路参考程序注释。

总结

递归果然简洁有力

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL