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. easyui form提交和formdata提交记录

    1  easyui form提交 $('form').form('submit',{ url:''; onSubmit:''; success:function(data){ //这种方法获取到的da ...

  2. B/S开发介绍

    b/s 的优势: 1.开发成本低 2.管理维护简单 3.产品升级便利 4.对用户的培训费用低 5.用户使用方便,出现故障的概率小 b/s 的不足: 1.安全性不足 2.客户端不能随心变化,受浏览器限制

  3. MVC HTML页面使用

    解决HTML <system.webServer> <validation validateIntegratedModeConfiguration="false" ...

  4. 【题解】Luogu P4679 [ZJOI2011]道馆之战

    原题传送门 码农题树剖好题,口袋妖怪是个好玩的游戏 这道题要用树链剖分,我博客里有对树链剖分的详细介绍 下文左右就代表树的节点按dfs序后的左右,上.下分别表示每个节点的A.B区域 考虑在链上的情况, ...

  5. 通过shell查找访问日志中访问量最大的ip

    日志格式: /Sep/::: +] /Sep/::: +] /Sep/::: +] - /Sep/::: +] - /Sep/::: +] /Sep/::: +] - /Sep/::: +] /Sep ...

  6. [c/c++] programming之路(4)、常量和变量

    一.打开多个程序(温习) #include<stdio.h> #include<stdlib.h> void main(){ ; ]; scanf("%d" ...

  7. webpack --watch和supervisor的不同

     webpack --watch只是热打包,也就是前端代码的热加载,要实现后端代码的热加载,也就是热部署,需要使用supervisor 如何使用热部署可以参考这里:http://www.cnblogs ...

  8. python脚本解析json文件

    python脚本解析json文件 没写完.但是有效果.初次尝试,写的比较不简洁... 比较烦的地方在于: 1,中文编码: pSpecs.decode('raw_unicode_escape') 2,花 ...

  9. EGIT

    https://jingyan.baidu.com/article/64d05a0262f013de55f73bcc.html

  10. topcoder srm 697 div1 -3

    1.给定长度为$n$ 的数组$b$,构造长度为$n$ 的且没有重复元素的数组$a$,令$p_{i}$表示$a$中除$a_{i}$外其他元素的乘积.构造出的$a$满足$a_{i}^{b_{i}}$能够被 ...