publicclassSolution{ publicintreverse(int x){ long rev = 0; // possible overflow while ( x != 0) { // no need to take care of negative value rev = rev * 10 + x % 10; // no need for an array to keep track of digits x = x / 10; if (rev > Integer.MAX_VALUE || rev < Integer.MIN_VALUE) // check for overflow while reversing return0; } return (int) rev; } }