Having fun on Leetcode with C++, Java, Python & GO
Problem 9. Palindrome Number
My attempt(s)
Code
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
class Solution {
public:
bool isPalindrome(int x) {
if (x<0)
return false;
long reversex=0;
int originx=x;
while (x!=0)
{
reversex=reversex*10+x%10;
x=x/10;
}
cout<<reversex;
if (originx==reversex)
return true;
else
return false;
}
};
|
Explanation of idea
Good solution ref.
Code
Analysis