class Solution { public: bool isPalindrome(int x) { int x1=x; int x2=x; int count=0; int num=0; int sum=0; while(x1>0)//得到未知整数的位数 { x1=x1/10; count++; } for(int i=0;i<=count;i++) { sum=sum*10+num;//逆置原整数 num=x2%10;//除10取余数; x2=x2/10; } if(sum==x) return true; else return false; } };
Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号