Ps: 看了左神的一節課程,他提出的這個方法來驗證數字的回文串確實很好,時間復雜度也比較小,
class Solution {
public:
bool ispalindrome(int n) {
if (n < 0) return false;
int help = 1;
while (n / help > 10) {
help = help * 10;
}
cout << help;
while (n != 0) {
if (n / help != n % 10) {
return false;
}
n = (n % help) / 10; // 高明
help = help / 100; // 要消掉2位
}
return true;
}
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/56845.html
標籤:C++
上一篇:CodeForces 1324 - Codeforces Round #627 (Div. 3)
下一篇:c++中的型別識別
