Title: Determine whether an integer is a palindrome. Do this without extra space.
At the beginning to see the topic when thinking of the stack to deal with, each come in a number and stack top elements of the same stack top elements at the stack, different elements into the stack, the last stack is empty or the remaining number is true, I was "1234321" to consider, but when the submission found that there is "100" This situation, So there are two types to deal with, odd numbers and even numbers.
Put 11 put the always absent-minded, afraid tired didn't go out to play, stay seems more tired. Brother and sister are out looking for work, God bless them.
The code is as follows:
1 classSolution:2 #@return A Boolean3 defIspalindrome (self, x):4 if(x<0):5 returnFalse6 elif(0<=x<10):7 returnTrue8 Else:9stack=[]TenTmp_str=str (x) One if(Len (TMP_STR)%2==0): A forIinchxrange (len (TMP_STR)): - if(len (stack) = =0): - stack.append (Tmp_str[i]) the elif(stack[-1]==Tmp_str[i]): - del(stack[-1]) - Else: - stack.append (Tmp_str[i]) + if(len (stack) = =0): - returnTrue + Else: A returnFalse at Else: -Mid=len (TMP_STR)/2 -Tmp_a=Tmp_str[0:mid] -End=Len (TMP_STR) -Tmp_b=tmp_str[mid+1: end] - if(tmp_a==tmp_b[::-1]): in returnTrue - Else: to returnFals
Leetcode palindrome Number Python