2013년 2월 13일 수요일

Reverse Integer

 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;
 }

댓글 없음:

댓글 쓰기