leetcode Algorithms 7. Reverse Integer

来源:互联网 发布:three.js 工具 编辑:程序博客网 时间:2024/05/20 01:44

题意:翻转一个整数,越界返回0;

思路:模拟;

class Solution {public:    int reverse(int x) {        long long ans=0;        while(x)        {            int z=x%10;            ans=ans*10+z;            x/=10;        }        if(ans>INT_MAX||ans<INT_MIN)return 0;        return ans;    }};

原创粉丝点击