feat: 9_palindrome_number
tmp
This commit is contained in:
parent
265aaca2b6
commit
1c8c5ed92d
19
9_palindrome_number/main.cpp
Normal file
19
9_palindrome_number/main.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
bool isPalindrome(int x) {
|
||||||
|
if (x < 0) return false;
|
||||||
|
|
||||||
|
string num = to_string(x);
|
||||||
|
int len = num.length();
|
||||||
|
for (int i = 0; i < len / 2; i++) {
|
||||||
|
if (num[i] != num[len - i - 1]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user