7. Reverse Integer

来源:互联网 发布:手机淘宝删除差评链接 编辑:程序博客网 时间:2024/06/15 13:30

Reverse digits of an integer.

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

click to show spoilers.

Subscribe to see which companies asked this question

public class Solution {    public int reverse(int x) {long res = 0; while (x != 0) { res = res * 10 + x % 10; x /= 10; } if (res > Integer.MAX_VALUE || res < Integer.MIN_VALUE) { return 0; } return (int) res;    }}

0 0
原创粉丝点击