feat: 3_palindrome_number
This commit is contained in:
parent
265aaca2b6
commit
633d55c588
19
3_palindrome_number/main.cpp
Normal file
19
3_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