Skip to content

Commit 6fbbb4d

Browse files
authored
Create Palindrome Number.cpp
1 parent 3091668 commit 6fbbb4d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

LeetCode/Palindrome Number.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
bool isPalindrome(int x) {
4+
if(x<0) return false;
5+
if(x<10) return true;
6+
int i=0;
7+
string s = to_string(x);
8+
int length = s.length();
9+
for(i=0; i<length; ++i) {
10+
if(s[i] != s[length-i-1]) break;
11+
}
12+
if(i == length) return true;
13+
return false;
14+
}
15+
};

0 commit comments

Comments
 (0)