请问这是怎么回事# Joke - 肚皮舞运动
a*e
1 楼
我觉得思路很简单,就是程序写不对。
下午还特别犯困,看到别的答案很简洁,自己的程序怎么调都通不过。
很郁闷。请问这种情况下自己花很多时间一步一步debug把程序写对到底值不值,还是
干脆找个标准答案记下来算啦?多谢指点。准备面试备受打击,觉得花在PH.D上的时间
还不如来趁年轻刷题啊。
bool isPalindrome(int x) {
if (x<0) return false;
if (x/10<1) return true;
int t = 1;
while(x/t>1)
t=t*10;
int a=1, b=t/10;
int left, right;
while (a<=b)
{
left = x/b;
right= (x%(a*10))/a;
if (left!=right)
return false;
else
{
x = x-left*b;
a=a*10;
b=b/10;
}
}
return true;
}
下午还特别犯困,看到别的答案很简洁,自己的程序怎么调都通不过。
很郁闷。请问这种情况下自己花很多时间一步一步debug把程序写对到底值不值,还是
干脆找个标准答案记下来算啦?多谢指点。准备面试备受打击,觉得花在PH.D上的时间
还不如来趁年轻刷题啊。
bool isPalindrome(int x) {
if (x<0) return false;
if (x/10<1) return true;
int t = 1;
while(x/t>1)
t=t*10;
int a=1, b=t/10;
int left, right;
while (a<=b)
{
left = x/b;
right= (x%(a*10))/a;
if (left!=right)
return false;
else
{
x = x-left*b;
a=a*10;
b=b/10;
}
}
return true;
}