Đề:
e lấy trong leetcode
chưa hiểu sao đáp án chưa đúng mn coi giúp em
class Solution {
public:
int reverse(int x) {
if(x<=-2^31||x>=2^31-1){
return 0;
}
bool ad;
if(-9<=x<=9){
return x;
}
if(x<0){
x=x*-1;
ad = false;
}
while(x%10==0){
x=x/10;
}
int so=0,n;
for(int i=0;i<2^31;i++){
n=x%(10*10^i);
so=so*10^i+n;
x=x-(10^i)*n;
if(x%10==x){
break;
}
}
if(ad==false){
so=so*-1;
}
return so;
}
};