LeetCode[7] 反转整数

Reverse digits of an integer.

Example1: x = 123, return 321

Example2: x = -123, return -321

My Solution

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

欢迎关注公众号: FullStackPlan 获取更多干货

Copyright © 2016 - 2017 LBD All Rights Reserved.

访客数 : | 访问量 :