题目考察的知识点:双指针
题目解答方法的文字分析:先找出小数点的位置,然后判断前后数据是否回文。
本题解析所用的编程语言:c++
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param x string字符串 * @return bool布尔型 */ bool isPalindromeNumber(string x) { // write code here int p1 = 0, p2 = 0; int t = 0; while (x[t] != '.') ++t; p2 = t - 1; while (p1 < p2) if (x[p1++] != x[p2--]) return false; p2 = x.size() - 1; while (x[p2] == '0') --p2; p1 = t + 1; while (p1 < p2) if (x[p1++] != x[p2--]) return false; return true; } };