源码
class Solution {
public:
int reverse(int x) {
bool flag = true;
if(x<0)
flag = false;
stringstream ss;
string s;
stack<char> STA;
string S;
ss<<x;
ss>>s;
for(auto it = s.begin();it!=s.end();it++)
{
STA.push(*it);
}
while(!STA.empty())
{
S.push_back(STA.top());
STA.pop();
}
long a = stol(S);
if(!flag)
a *=-1;
if(a>pow(2, 31) - 1||a<-1*pow(2, 31))
return 0;
else
return (int)a;
}
};
好像不管x是正是负,压到stringstream里,再弹出来就没负号了,实际上是这样吗??
stringstream会无视符号吗
现象上好像是这样