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

16 lines
206 B
Ruby
Raw Normal View History

2022-11-28 22:34:01 +05:00
# @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