Determine whether an integer is a palindrome. Do this without extra space.
自己之前的想法是先转换成字符串模式,然后首尾同时开始遍历比较,如果不同则非回文。
但是这个要求是不能有额外的空间。所以在网上查找了其他算法,看到是太惊叹了(自己算法能力太水)。
bool isPalinNumber(long n){ /*倒转高低位*/ long temp = n; long ret; while( temp > 0 ){ ret = ret*10 + temp%10; temp /= 10; } if(ret == n) return 1; else return 0; }