Last active
March 13, 2024 21:28
-
-
Save cwgreene/6323852c47570b55ec3495ca9d358837 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def divide(self, dividend: int, divisor: int) -> int: | |
sign = 1 | |
if dividend < 0: | |
dividend = - dividend | |
sign = - sign | |
if divisor < 0: | |
sign = - sign | |
divisor = - divisor | |
piles = [[] for _ in range(divisor)] | |
objects = [0 for _ in range(dividend)] | |
index = 0 | |
# sort into piles | |
while objects: | |
object = objects.pop() | |
piles[index].append(object) | |
index += 1 | |
# handle mod | |
if index >= divisor: | |
index = 0 | |
result = min(len(pile) for pile in piles) | |
if sign < 0: | |
result = - result | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment