[Leetcode]_7 Reverse Integer

来源:互联网 发布:淘宝关键词排名不稳定 编辑:程序博客网 时间:2024/05/22 14:34

注意值范围
然后,就没了。

/** *  Index: 7 *  Title: Reverse Integer *  Author: ltree98 **/class Solution {public:    int reverse(int x) {            long long ans = 0;        while( x != 0 ) {            int temp = x % 10;            ans = ans*10 + temp;            x /= 10;        }        if(ans > INT_MAX || ans < INT_MIN)            return 0;                return int(ans);    }};
0 0
原创粉丝点击