Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
public class Solution { public int reverse(int x) { // Start typing your Java solution below // DO NOT write main() function int num = Math.abs(x); int carry = 0; while(num!= 0){ carry = 10*carry + num%10; num = num/10; } if(x>0) return carry; else return -1 * carry; } }