标签:判断 pow ++ return log 字符串 int false blog
//判断数组是否是回文 不能用字符串作为辅助,也不能翻转数字(有溢出情况);
class Solution { public: bool isPalindrome(int x) { if(x < 0) return false; if(x <10) return true; int digits = 0; int t = x; int cnt = 0; while(t != 0) { t /= 10; ++cnt; } int left = pow(10,cnt-1); int right = 1; while(left >= right){ if(x/left%10 != x/right%10) return false; left /= 10; right *= 10; } return true; } };
标签:判断 pow ++ return log 字符串 int false blog
原文地址:http://www.cnblogs.com/xiuxiu55/p/6512815.html