标签:.com turn lintcode csdn 超出 get des 参考 问题
原题网址:https://www.lintcode.com/problem/reverse-integer/description
将一个整数中的数字进行颠倒,当颠倒后的整数溢出时,返回 0 (标记为 32 位整数)。
给定 x = 123
,返回 321
给定 x = -123
,返回 -321
class Solution {
public:
/**
* @param n: the integer to be reversed
* @return: the reversed integer
*/
int reverseInteger(int n) {
// write your code here
int m=n,result=0;
vector<int> tmp;
while(m)
{
tmp.push_back(m%10);
m=m/10;
}
int size=tmp.size();
for (int i=0;i<size;i++)
{
result=result+tmp[i]*pow(10.0,size-1-i);
if (result>=INT_MAX||result<=INT_MIN)
{
return 0;
}
}
return result;
}
};
其他思路:
https://blog.csdn.net/zsjmfy/article/details/53405494
https://www.cnblogs.com/grandyang/p/5778281.html 代码精简
https://blog.csdn.net/qq_23225317/article/details/53641864
标签:.com turn lintcode csdn 超出 get des 参考 问题
原文地址:https://www.cnblogs.com/Tang-tangt/p/9220772.html