[LeetCode][python3]0029. Divide Two Integers

  1. My first solution
class Solution:
def divide(self, dividend: int, divisor: int) -> int:
d=False
if dividend<0:
d=not d
dividend=-dividend
if divisor<0:
divisor=-divisor
d=not d
res=dividend//divisor
if d:
res=-res
if res>2147483647:
return 2147483647
elif res<-2147483648:
return -2147483648
else:
return res

--

--

--

HI I’m N2I. Now a SWE in Taiwan. Check out more about me in https://nzi2020.blogspot.com/ or contact via email: nayzi9999@gmail.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Right filter syntax for the [z,p,k] syntax

Algorand Bounty Hack Recap!

Talking Python Logging Handler

Setting Up the Security Cameras

CSS Display Property

Release Notes: Eclipse Che 6.0

Podcasts We Can’t Live Without

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
N2I

N2I

HI I’m N2I. Now a SWE in Taiwan. Check out more about me in https://nzi2020.blogspot.com/ or contact via email: nayzi9999@gmail.com

More from Medium

Leetcode Blind 75 practice — Contains duplicate

Hackerrank — Insert Node in linked list walkthrough #Python #Hackerrank

LeetCode #1695 | Maximum Erasure Value (Python)

LeetCode 153. Find Minimum in Rotated Sorted Array — Python Solution