Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
# @param {Integer} x
# @return {Boolean}
def is_palindrome(x)
return false if x.negative?
if x.positive?
arr = x.to_s.chars
size = arr.size
arr.each_with_index do |ele, idx|
return false if ele != arr[size - idx - 1]
end
return true
end
return true if x.zero?
end
Coud you solve it without converting the integer to a string?
文字列に変換しないパターンは思いつかなかった🙃