面试经典150题 P9 回文数
时间轴
2025-11-26
init
题目:
to_string直接比较字符串去吧1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using std::string;
class Solution {
public:
bool isPalindrome(int x)
{
if (x < 0) {
return false;
}
string s1 = std::to_string(x);
string s2(s1);
std::reverse(s2.begin(), s2.end());
if (s1.compare(s2) == 0) {
return true;
}
return false;
}
};
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 常想一二,不思八九!
评论





