classSolution:defreverse(self,x:int)->int:# Init varsdigit_list=[]positive=Trueifx>0elseFalseifnotpositive:x=-x# Store each digits to stackwhilex!=0:digit=x%10digit_list.append(digit)x=int(x/10)# Make up resultresult=0whilelen(digit_list)!=0:result=result*10digit=digit_list.pop(0)result=result+digitifresult>2147483647:return0ifpositive:returnresultelse:return-result