Created
June 12, 2020 18:36
-
-
Save cfc1020/c1b11d1a7f03c1528d27e72aba7a84bd to your computer and use it in GitHub Desktop.
Palindrome Number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @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