leetcode-7

leetcode-7

*Given a 32-bit signed integer, reverse digits of an integer.

Example 1:

Input: 123
Output: 321
Example 2:

Input: -123
Output: -321
Example 3:

Input: 120
Output: 21*/

public class Solution7 {
	
	
	 public int reverse(int x) {
	        long n = 0;
	        while(x != 0) {
	            n = n*10 + x%10;
	            x = x/10;
	        }
	        return (int)n==n? (int)n:0;
	    }


}

你可能感兴趣的:(算法,leetcode,java)