Reverse integer

来源:互联网 发布:打折是怎么个算法 编辑:程序博客网 时间:2024/05/02 22:09
class Solution {public:    int reverse(int x) {        // Note: The Solution object is instantiated only once and is reused by each test case.        int res=0;        int flag=1;        if (x<0) {            flag=-1;            x=x*(-1);        }        while(x>=10) {            res +=x%10;            x=x/10;            res=res*10;        }        res+=x;        if (flag==-1) {            res=res*(-1);        }        return res;    }};

原创粉丝点击