Skip to content

Commit 2329547

Browse files
authored
Create 009. Palindrome Number.cpp
1 parent 2c7d9d2 commit 2329547

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

C++/009. Palindrome Number.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
bool isPalindrome(int x) {
4+
if (x < 0 || (x != 0 && x%10 == 0)) return false;
5+
int y = 0;
6+
while (x > y){
7+
y = y*10 + x%10;
8+
x = x/10;
9+
}
10+
return (x==y || x==y/10);
11+
}
12+
};

0 commit comments

Comments
 (0)