public int reverse(int x) { boolean negativeSign = false; if (x < 0) { negativeSign = true; x *= -1; } int rv = 0; while (x > 0) { rv *= 10; rv += (x % 10); x /= 10; } if (negativeSign) rv *= -1; return rv; }
댓글 없음:
댓글 쓰기