RosettaCodeData/Task/Longest-common-subsequence/OCaml/longest-common-subsequence-1.ml
2024-10-16 18:07:41 -07:00

10 lines
240 B
OCaml

let longest xs ys = if List.length xs > List.length ys then xs else ys
let rec lcs a b = match a, b with
[], _
| _, [] -> []
| x::xs, y::ys ->
if x = y then
x :: lcs xs ys
else
longest (lcs a ys) (lcs xs b)