LeetCode 筆記 - 29. Divide Two Integers

題目在此 29. Divide Two Integers

請將兩個數字相除

解題思維

這題其實沒有太多事情可以做,注意一下 Overflow 就可以了

程式碼

1
2
3
4
5
6
7
8
class Solution:
def divide(self, dividend: int, divisor: int) -> int:
result = int(dividend / divisor)

if result > 2147483647:
return 2147483647

return result

相關文章