Skip to content

Commit

Permalink
solution for destination city using elixir
Browse files Browse the repository at this point in the history
  • Loading branch information
xsami committed Jan 6, 2024
1 parent 1362581 commit 04866e0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions DestinationCity/destinationCity.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Solution for: https://leetcode.com/problems/destination-city/description/
defmodule Solution do

defp get_empty_city([], map), do: map

defp get_empty_city([[from, to] | tail], map) do
get_empty_city(tail, Map.put(map, from, to))
end

@spec dest_city(paths :: [[String.t]]) :: String.t
def dest_city(paths) do
map = get_empty_city(paths, %{})
map |> Enum.reduce("", fn({k, v}, acc) ->
if map[v] != nil do
acc
else
v
end
end)
end
end

0 comments on commit 04866e0

Please sign in to comment.