RosettaCodeData/Task/Longest-common-subsequence/OCaml/longest-common-subsequence-1.ocaml
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

10 lines
240 B
Text

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)