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 ...
随机推荐
- 前端框架VUE----babel
这个是解析我们es6的代码的,为什么要用它呢,因为对于一些ie浏览器,甚至FF浏览器,低版本的还不能识别我们的es6代码,那么vue里面好多还让我们去写es6的代码,这个时候我们就可以用babel这个 ...
- Django框架----用户认证auth模块
一.auth模块 auth模块:针对auth_user表 创建超级管理用户命令: Python manage.py createsuperuser添加用户名添加密码(至少8位)确认密码添加邮箱(可为空 ...
- 从源码层面聊聊面试问烂了的 Spring AOP与SpringMVC
Spring AOP ,SpringMVC ,这两个应该是国内面试必问题,网上有很多答案,其实背背就可以.但今天笔者带大家一起深入浅出源码,看看他的原理.以期让印象更加深刻,面试的时候游刃有余. Sp ...
- 每日linux命令学习-引用符号(反斜杠\,单引号'',双引号"")
引用符号在解析器中保护特殊元字符和参数扩展,其使用方法有3种:反斜杠(\),单引号(’‘),双引号(“”). 单引号和双引号必须匹配使用,均可在解析器中保护特殊元字符和通配符,但是单引号(硬转义)主要 ...
- Python3 自定义请求头消息headers
Python3 自定义请求头消息headers 使用python爬虫爬取数据的时候,经常会遇到一些网站的反爬虫措施,一般就是针对于headers中的User-Agent,如果没有对headers进行设 ...
- Git 安装和使用教程(转载)
转载:https://www.cnblogs.com/smuxiaolei/p/7484678.html 转载:https://blog.csdn.net/wk_1214BoKe/article/de ...
- InstallShield.12完美使用
转载:http://www.360doc.com/content/13/0517/10/7918060_286039102.shtml 转载:http://jingyan.baidu.com/arti ...
- Markdon 作图语法 CSDN
插入甘特图 gantt dateFormat YYYY-MM-DD title Adding GANTT diagram functionality to mermaid section 现有任务 已 ...
- 【lg1799】数列
题目描述 虽然msh长大了,但她还是很喜欢找点游戏自娱自乐.有一天,她在纸上写了一串数字:1,l,2,5,4.接着她擦掉了一个l,结果发现剩下l,2,4都在自己所在的位置上,即1在第1位,2在第2位, ...
- gimp的使用笔记
gimp是德国的开源软件! 跟其他软件一样, 包括file, edit, view, 还有select, color , filter, 和 window. 窗口window就包括所有的dockabl ...