import math class Solution(object): def divide(self, dividend, divisor): """ :type dividend: int :type divisor: int :rtype: int """ self.dividend = dividend self.divisor = divisor a = int(operator.truediv(dividend, divisor)) if a >= 2**31 or a < -2**31: return 2**31 - 1 else: return a
python的除法在负数是向下取整,而本题需要向上取整
python中求幂的算法是**而不是^