leetcode Divide Two Integers python
class Solution(object):
def divide(self, dividend, divisor):
"""
:type dividend: int
:type divisor: int
:rtype: int
"""
flag=-1
if ( dividend > 0 and divisor >0 ) or ( dividend < 0 and divisor < 0 ):
flag=1
dividend=abs(dividend)
divisor=abs(divisor)
quotient=0
while dividend >= divisor:
k=0
tmp=divisor
while dividend >= tmp:
quotient += 1 << k
dividend -= tmp
tmp <<=1
k+=1 if flag > 0:
if quotient > 2147483647:
quotient = 2147483647
return quotient
else:
return -quotient
@link http://chaoren.is-programmer.com/posts/43017.html
leetcode Divide Two Integers python的更多相关文章
- [LeetCode] Divide Two Integers 两数相除
Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...
- LeetCode: Divide Two Integers 解题报告
Divide Two Integers Divide two integers without using multiplication, division and mod operator. SOL ...
- Leetcode Divide Two Integers
Divide two integers without using multiplication, division and mod operator. 不用乘.除.求余操作,返回两整数相除的结果,结 ...
- [LeetCode] Divide Two Integers( bit + 二分法 )
Divide two integers without using multiplication, division and mod operator. 常常出现大的负数,无法用abs()转换成正数的 ...
- Leetcode:Divide Two Integers分析和实现
题目要求我们用一个32位整数整除另外一个整数,但是不允许我们使用除法,乘法和取模运算. 有趣的问题,下面说一下我的思路: 首先,先给出两个正整数除法运算的过程.假设a为被除数,而b为除数.在计算机中无 ...
- [Leetcode][Python]29: Divide Two Integers
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 29: Divide Two Integershttps://oj.leetc ...
- leetcode面试准备:Divide Two Integers
leetcode面试准备:Divide Two Integers 1 题目 Divide two integers without using multiplication, division and ...
- 【一天一道LeetCode】#29. Divide Two Integers
一天一道LeetCode系列 (一)题目 Divide two integers without using multiplication, division and mod operator. If ...
- 【Leetcode】【Medium】Divide Two Integers
Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...
随机推荐
- android分割线
http://blog.csdn.net/dekunchenivan/article/details/6640804 在Android布局文件layout中设置水平分割线: <View ...
- Apache Lens —— 统计数据分析查询接口
Lens 提供了一个统一数据分析接口.通过提供一个跨多个数据存储的单一视图来实现数据分析任务切分,同时优化了执行的环境.无缝的集成 Hadoop 实现类似传统数据仓库的功能. 该项目主要特性: 简单元 ...
- asp.net 总结
asp.net 是服务器段控件,运行是返回一个客户端html 页面给服务器
- Free Sql Server SMSS format Plugin
免费Sql Server 格式化插件 http://www.apexsql.com/sql_tools_refactor.aspx http://architectshack.com/PoorMans ...
- HTML8表单验证
表单验证: 一.非空验证: 1.内容是不是空的. 判断值的长度是不是0.length属性.压缩空格的函数. 2.内容是不是改变了. 二.对比验证: 1.验证两个控件值的关系(相同,大小) ...
- JSP 最佳实践: 用 jsp:include 控制动态内容
在新的 JSP 最佳实践系列的前一篇文章中,您了解了如何使用 JSP include 伪指令将诸如页眉.页脚和导航组件之类的静态内容包含到 Web 页面中.和服务器端包含一样,JSP include ...
- 诡异的_DEBUG宏
学习VLD1.0代码,发现Release版本的代码_DEBUG宏是已定义的,查找工程配置确只有NDEBUG宏的定义,不见_DEBUG的踪影. 好吧,最后发现是由于工程Code Generation选项 ...
- php学习网址
后面会陆续维护此页. 1. php编程 此博客是网站www.beilei123.cn镜像,转载请注明出处.
- 分享个人如何DIY网站的经验
对于一个接触过Web开发的IT人来说,一般都考虑过创建属于自己的网站,可能是定制自己特有风格的博客类网站,可能是私密的个人主页,也可能是展示自己开源工具的网站,当然,酝酿着做个商业网站来创业的人肯定也 ...
- RSA—非对称加密算法
RSA:非对称加密算法加解密原理如下:已知:p,q,n,e,d,m,c其中:p与q互为大质数,n=p*q 公钥Pk(n,e):加密使用,是公开的 私钥Sk(n,d):解密使用,不公开 c:明文 m:密 ...