Skip to content

Instantly share code, notes, and snippets.

@cfc1020
Created June 12, 2020 18:36
Show Gist options
  • Save cfc1020/c1b11d1a7f03c1528d27e72aba7a84bd to your computer and use it in GitHub Desktop.
Save cfc1020/c1b11d1a7f03c1528d27e72aba7a84bd to your computer and use it in GitHub Desktop.
Palindrome Number
# @param {Integer} x
# @return {Boolean}
def is_palindrome(x)
return false if x.negative?
s = x.abs.to_s
i = 0
j = s.length - 1
while i < j do
return false if s[i] != s[j]
i += 1
j -= 1
end
true
end
# @param {Integer} x
# @return {Boolean}
def is_palindrome(x)
x.to_s == x.to_s.reverse
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment