Leetcode palindrome Number Python

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.