All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0001_0100.s0009_palindrome_number.Solution.ex Maven / Gradle / Ivy

There is a newer version: 1.8
Show newest version
# #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