Determine whether an integer is a palindrome. Do this without extra space. 解析:把该整数倒转过来,如果和原来的数字相等,则说明是回文整数。注意:任何负数都不是回文整数。bool isPalindrome(int x) { if (x < 0) return false; int res = 0; int val = x; while (val) { res = res * 10 + val % 10; val /= 10; } if (res == x) return true; else return false; }
Palindrome Number(回文整数)
最新推荐文章于 2020-12-08 11:03:25 发布