标签:
题目来源:https://leetcode.com/problems/reverse-integer/
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
解题思路:
1 public class Solution { 2 public int reverse(int x) { 3 long reverse = 0; 4 5 while(x != 0){ 6 reverse = reverse * 10 + x % 10; 7 if(reverse > Integer.MAX_VALUE || reverse < Integer.MIN_VALUE) 8 return 0; 9 x = x / 10; 10 } 11 return (int)reverse; 12 } 13 }
LeetCode 7 Reverse Integer(反转数字)
标签:
原文地址:http://www.cnblogs.com/zpfbuaa/p/5076819.html