my-solutions/problems/9-palindrome-number/main.rb

15 lines
206 B
Ruby

# @param {Integer} x
# @return {Boolean}
def is_palindrome(x)
return false if x.negative?
copy = x
inv = 0
while copy.positive?
inv = inv * 10 + copy % 10
copy /= 10
end
inv == x
end