Cover image for 面试经典150题 P9 回文数

面试经典150题 P9 回文数


时间轴

时间轴

2025-11-26

init

数学

题目:

to_string 直接比较字符串去吧

123456789101112131415161718192021
#include <string>#include <algorithm>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;	}};
评论加载中…