classSolution(object): defreverse(self, x): """ :type x: int :rtype: int """ if x == 0: return x if x < 0: neg = True x = -x else: neg = False revx = 0 while x > 0: revx = revx * 10 + x % 10 x //= 10 if len(bin(revx)[2:]) >= 32: return0 else: return -revx if neg else revx