0
交叉口[1; 2; 2; 3; 4; 4; 3] [2; 3] = [2; 2; 3; 3]ocaml的遞歸
沒有與我的代碼,因爲它目前一些錯誤返回[2; 2],因爲它不會與t2匹配,只有h2,有沒有人有任何建議我應該考慮改變這個方向?
let rec intersection (l1: int list) (l2: int list) : int list =
begin match l1, l2 with
| h1::t1, h2::t2 -> if h1=h2 then h1::intersection t1 l2
else intersection t1 l2
| _ -> []
end
謝謝你的有用評論! (正式註明) – user