Palindrome Number Leetcode Python Java

来源:互联网 发布:java可以清理cookie吗 编辑:程序博客网 时间:2024/05/20 13:36

Palindrome Number

Total Accepted: 131143 Total Submissions: 406290 Difficulty: Easy

Determine whether an integer is a palindrome. Do this without extra space.

Java:

public class Solution{        public boolean palindromeNumber(int x){                ling tmp=0;                start=x;                while(x!=0){                        int tail=x%10;                        int newsult=tmp*10+tail;                        if(newsult>INT_MAX||newsult<INT_MIN){                                return false;                        }                        tmp=newsult                        x=x/10                }                if(result==start){                        return ture;                }                else{                        return false;                }        }}
Python:

class SOlution:        def palindromeNumber(self,x):                tmp=0                start=x                while x!=0:                        tail=x%10                        newsult=tmp*10+tail                        if(newsult-tail)/10!=tmp:                                return False                        tmp=newsult                        x=x/10                if start==tmp:                        return True                else:                        return False


0 0