描述:不使用 * / % 完成除法操作。O(n)复杂度会超时,需要O(lg(n))复杂度。

代码:

 class Solution:
# @return an integer
def dividePositive(self, dividend, divisor):
if dividend < divisor:
return 0 sum = divisor
count = 1
while sum + sum < dividend:
sum += sum
count += count count += self.dividePositive(dividend - sum, divisor) return count def divide(self, dividend, divisor):
if dividend >= 0:
if divisor > 0:
return self.dividePositive(dividend, divisor)
else:
return 0 - self.dividePositive(dividend, 0 - divisor)
else:
if divisor > 0:
return 0 - self.dividePositive(0 - dividend, divisor)
else:
return self.dividePositive(0 - dividend, 0 - divisor)

#Leet Code# Divide Two Integers的更多相关文章

  1. Divide Two Integers leetcode

    题目:Divide Two Integers Divide two integers without using multiplication, division and mod operator. ...

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

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

  3. LeetCode: Divide Two Integers 解题报告

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

  4. 算法练习--LeetCode--29. Divide Two Integers

    Divide Two Integers Given two integers dividend and divisor, divide two integers without using multi ...

  5. [LeetCode] Divide Two Integers 两数相除

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

  6. Leetcode Divide Two Integers

    Divide two integers without using multiplication, division and mod operator. 不用乘.除.求余操作,返回两整数相除的结果,结 ...

  7. leetcode-【中等题】Divide Two Integers

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

  8. [LintCode] Divide Two Integers 两数相除

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

  9. 62. Divide Two Integers

    Divide Two Integers Divide two integers without using multiplication, division and mod operator. 思路: ...

随机推荐

  1. PyDev+eclipse的编码问题

    1.在代码的开始声明编码为utf-8

  2. iOS中SQLite知识点总结1

    数据库(SQLite) 01-数据库简介 1.什么是数据库 数据库(Database)是按照数据结构来组织,存储和管理数据的仓库 2.数据库的分类 关系型数据库(主流) PC端:Oracle/MySQ ...

  3. FZU2132 - LQX的作业(概率论)

    Problem Description LQX在做作业时遇到一个难题不会做,请你帮她计算一下:在N个独立地分布于0和1之间的随机变量排为非递减顺序之后,这些变量中第M个小于等于x的概率是多少? Inp ...

  4. linux使用FIO测试磁盘的iops 【转载】

     linux使用FIO测试磁盘的iops 2013-09-23 10:59:21 分类: LINUX FIO是测试IOPS的非常好的工具,用来对硬件进行压力测试和验证,支持13种不同的I/O引擎,包括 ...

  5. WinForm TextBox自定义扩展方法数据验证

    本文转载:http://www.cnblogs.com/gis-crazy/archive/2013/03/17/2964132.html 查看公司项目代码时,存在这样一个问题:winform界面上有 ...

  6. Ubuntu14.04搭建cocos2dx2.2.5开发环境(超级具体)

    一 下载解压 官方下载地址:http://www.cocos2d-x.org/download 下载下来之后解压完毕之后会得到一个文件夹cocos2d-x-2.2.5 二 编译 1 安装依赖 cd到c ...

  7. 在LAMP环境下搭建JSP动态网页

    开发环境Linux的版本号Linux localhost.localdomain 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x ...

  8. android80 HttpClient框架提交数据 get方式

    package com.itheima.httpclient; import java.io.IOException; import java.io.InputStream; import java. ...

  9. NVMe 图解

    http://www.ssdfans.com/?p=1143#rd&sukey=3997c0719f151520989740bb972a716fdb2dbab623808d16acd5075b ...

  10. 【转】cocos2d-x中锚点设置及定位方式

    http://blog.csdn.net/wayne5ning/article/details/8160506 说在前面:以下是基于cocos2d-2.0-x-2.0.3作的总结 问题 在cocos2 ...