leetcode 29-> Divide Two Integers without using multiplication, division and mod operator
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的更多相关文章
- 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 ...
- Divide two integers without using multiplication, division and mod operator.
描述 不能使用乘法.除法和取模(mod)等运算,除开两个数得到结果,如果内存溢出则返回Integer类型的最大值.解释一下就是:输入两个数,第一个数是被除数dividend,第二个是除数divisor ...
- [LeetCode] 29. Divide Two Integers 两数相除
Given two integers dividend and divisor, divide two integers without using multiplication, division ...
- Java [leetcode 29]Divide Two Integers
题目描述: Divide two integers without using multiplication, division and mod operator. If it is overflow ...
- [leetcode]29. Divide Two Integers两整数相除
Given two integers dividend and divisor, divide two integers without using multiplication, divisio ...
- [LeetCode] 29. Divide Two Integers(不使用乘除取模,求两数相除) ☆☆☆
转载:https://blog.csdn.net/Lynn_Baby/article/details/80624180 Given two integers dividend and divisor, ...
- [leetcode]29. Divide Two Integers 两整数相除
Given two integers dividend and divisor, divide two integers without using multiplication, division ...
- [LeetCode] 29. Divide Two Integers ☆☆
Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...
- [LeetCode]29. Divide Two Integers两数相除
Given two integers dividend and divisor, divide two integers without using multiplication, division ...
随机推荐
- Java中使用自定义类封装数组,添加类方法实现数据操作
1.具体见注释 2.后续或有更新 public class MyArray { private long[] array; private int cnt; // 自定义数组类的元素个数 /** 使用 ...
- Linux环境nginx的安装
安装Nginx前需要编译环境和库文件支持: 1.安装make: yum -y install openssl openssl-devel yum -y install gcc automake aut ...
- 给PHP开启shmop扩展实现共享内存
在项目开发中,想要实现PHP多个进程之间共享数据的功能,让客户端连接能够共享一个状态,需要开启共享内存函数shmop.如果预期考虑会遇到这方面需求,那么最好在编译PHP的时候添加--with-shmo ...
- roon
http://www.sthifi.com/Article/ViewArticle.asp?id=10895 http://kb.roonlabs.com/LinuxInstall https://c ...
- Linux Centos 7.4 内核升级
Linux Centos 7.4 内核升级 原始内核版本:3.10.0-693.2.2.el7.x86_64 升级内核版本:4.14.9-1.el7.elrepo.x86_64 1.导入key Key ...
- oracle orion hugepages_settings.sh(支持OEL 7,4.1内核)
orion需要首先配置hugepage,否则会出现下列错误. [root@yyxxdb01 ~]# /opt/app/11.2.0/grid_home/bin/orion -run oltp -tes ...
- MVC HTML页面使用
解决HTML <system.webServer> <validation validateIntegratedModeConfiguration="false" ...
- Windows Media Player添加播放插件
- POJ 1251 + HDU 1301 Jungle Roads 【最小生成树】
题解 这是一道裸的最小生成树题,拿来练手,题目就不放了 个人理解 Prim有些类似最短路和贪心,不断找距当前点最小距离的点 Kruskal类似于并查集,不断找最小的边,如果不是一棵树的节点就合并为一 ...
- bzoj 3437 小p的农场
bzoj 3437 小p的农场 思路 \(f[i]=min(f[j]+\sum\limits_{k=j+1}^{i}{b[k]*(i-k)}+a[i])\) \(f[i]=min(f[j]+\sum\ ...