class Solution(object):
def divide(self, dividend, divisor):
"""
:type dividend: int
:type divisor: int
:rtype: int
"""
ispositive = True
if dividend > and divisor < :
ispositive = False
if dividend < and divisor > :
ispositive = False
dividend = abs(dividend);divisor = abs(divisor)
if dividend < divisor:
return
num = [,,,,,,,,,]
i =
newdividend = []
while i >= :
tmp =
while dividend >= num[i]:
tmp += ;dividend -= num[i]
newdividend.append(tmp); i -=
tmpm = ; ans = ;i =
while i < :
while tmpm < divisor:
if i > :
break
j = ; t =
while j < and tmpm != :
t += tmpm; j +=
tmpm = t + newdividend[i]; i +=
if tmpm < divisor:
j = ; t =
while j < and ans != :
t += ans; j +=
ans = t
if tmpm >= divisor:
k =
while tmpm >= divisor:
tmpm -= divisor; k +=
j = ; t =
while j < and ans != :
t += ans; j +=
ans = t + k
if ispositive:
if ans > :
return
return ans
if ans >= :
return -
return - ans

leetcode 29-> Divide Two Integers without using multiplication, division and mod operator的更多相关文章

  1. algorithm@ Divide two integers without using multiplication, division and mod operator. (Bit Operation)

    #include<bits/stdc++.h> using namespace std; int divide(int dividend, int divisor) { long long ...

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

    描述 不能使用乘法.除法和取模(mod)等运算,除开两个数得到结果,如果内存溢出则返回Integer类型的最大值.解释一下就是:输入两个数,第一个数是被除数dividend,第二个是除数divisor ...

  3. [LeetCode] 29. Divide Two Integers 两数相除

    Given two integers dividend and divisor, divide two integers without using multiplication, division ...

  4. Java [leetcode 29]Divide Two Integers

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

  5. [leetcode]29. Divide Two Integers两整数相除

      Given two integers dividend and divisor, divide two integers without using multiplication, divisio ...

  6. [LeetCode] 29. Divide Two Integers(不使用乘除取模,求两数相除) ☆☆☆

    转载:https://blog.csdn.net/Lynn_Baby/article/details/80624180 Given two integers dividend and divisor, ...

  7. [leetcode]29. Divide Two Integers 两整数相除

    Given two integers dividend and divisor, divide two integers without using multiplication, division ...

  8. [LeetCode] 29. Divide Two Integers ☆☆

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

  9. [LeetCode]29. Divide Two Integers两数相除

    Given two integers dividend and divisor, divide two integers without using multiplication, division ...

随机推荐

  1. python-数据分析与展示(Numpy、matplotlib、pandas)---3

    笔记内容整理自mooc上北京理工大学嵩天老师python系列课程数据分析与展示,本人小白一枚,如有不对,多加指正 0.pandas基于Numpy实现的,前者注重应用,后者注重结构 1.Series类型 ...

  2. jpg、gif、png-8、png-24的区别

    一.gif格式的特点 1.透明性.gif是一种布尔透明类型,即它可以是全透明,也可以是全不透明,但是没有半透明 2.动画.gif支持动画 3.无损耗性.gif是一种无损耗的图像格式,这意味着你可以对g ...

  3. 【js】手机浏览器端唤起app,没有app就去下载app 的方法

    这种功能的作用: 1.一般公司有自己的app,而app是需要不断有新用户涌入才能持续运营,达到不错的收入.就需要使用这种方式进行引入新的用户. 2.一些内容在网页端体验不好,或者一些功能需要app内才 ...

  4. 学写网页 #06# table

    A B E C D <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> & ...

  5. django ORM模型表的一对多、多对多关系、万能双下划线查询

    一.外键使用 在 MySQL 中,如果使用InnoDB引擎,则支持外键约束.(另一种常用的MyIsam引擎不支持外键) 定义外键的语法为fieldname=models.ForeignKey(to_c ...

  6. Eclipse启动参数设置

    Eclipse启动参数设置 文件路径:安装目录根路径/eclipse.ini 参数注解: [-debug options -vm javaw.exe] 显示JVM当前内存使用量(注:详见下方<让 ...

  7. 那些不错的 [ Html5 + CSS3 + Canvas ] 效果!

    apng制作工具:http://isparta.github.io/how.html apng制作文章:http://isux.tencent.com/introduction-of-apng.htm ...

  8. Windows环境下ELK平台的搭建

    .背景 日志主要包括系统日志.应用程序日志和安全日志.系统运维和开发人员可以通过日志了解服务器软硬件信息.检查配置过程中的错误及错误发生的原因.经常分析日志可以了解服务器的负荷,性能安全性,从而及时采 ...

  9. 02: http

    1.1 http简介 1.什么是http 1. HTTP是一个客户端和服务器端请求和应答的标准(TCP) 2. 设计HTTP最初的目的是为了提供一种发布和接收HTML页面的方法 2.http报文格式 ...

  10. python简说(一)if,for等

    一.python简说 python可以用于自动化测试.web开发.数据分析.AI python.自动化运维,第三方模块最多的一个语言. 编译型语言 c.c++ 要运行,先要编译,编译成二进制的. 解释 ...