Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. class Solution:
  2.     def get_sign(self, x, y):
  3.         if (x >= 0 and y >= 0) or (x < 0 and y < 0):
  4.             return +1
  5.         else:
  6.             return -1
  7.        
  8.     def divide(self, dividend, divisor):
  9.         sign = self.get_sign(dividend, divisor)        
  10.         def rec(x, y, powy, logy):
  11.             print((x, y, powy, logy))
  12.             if x < y:
  13.                 return 0
  14.             else:                
  15.                 n_powy = powy + powy
  16.                 n_logy = logy + logy
  17.                 if n_powy > x:
  18.                     return logy + rec(x - powy, y, y, 1)
  19.                 else:
  20.                     return rec(x, y, n_powy, n_logy)
  21.         x, y = abs(dividend), abs(divisor)
  22.         ans = sign * rec(x, y, y, 1)
  23.         return max(-2147483648, min(2147483647, ans))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement