LeetCode : Reverse Integer

来源:互联网 发布:centos7安装mysql 编辑:程序博客网 时间:2024/06/06 12:04

Reverse digits of an integer.

Example1: x = 123, return 321
Example2: x = -123, return -321

class Solution {public:    int reverse(int x) {        int res = 0;        while (x != 0) {            if (abs(res) > INT_MAX / 10) return 0;            res = res * 10 + x % 10;            x /= 10;        }        return res;    }};
0 0
原创粉丝点击