
g0001_0100.s0009_palindrome_number.Solution.ex Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-all Show documentation
Show all versions of leetcode-in-all Show documentation
104 LeetCode algorithm problem solutions
# #Easy #Math #Udemy_Integers #2024_07_31_Time_1007_ms_(87.50%)_Space_72_MB_(33.93%)
defmodule Solution do
@spec is_palindrome(x :: integer) :: boolean
def is_palindrome(x) when x < 0, do: false
def is_palindrome(x) when x < 10, do: true
def is_palindrome(x) do
reversed = x
|> Integer.digits
|> Enum.reverse
|> Integer.undigits
x == reversed
end
end
© 2015 - 2025 Weber Informatics LLC | Privacy Policy