lytlang/test/fixtures/tiny.lyt

14 lines
339 B
Text
Raw Permalink Normal View History

2019-05-11 13:01:39 -05:00
!mod Leetcode
@doc
LeetCode #1: two_sum
TODO: store a map of complements (differences) as iterating for O(n)
fn two_sum _:list _:int i=0 ::
[] _ _ -> nil
[cur | rest] target current_index
Enum.find_index rest, fn x -> cur + x == target ::
nil -> two_sum rest target current_index
i -> [current_index, 1 + current_index + i]