Common elements in two lists with duplicates
问题 I want to find the common elements in two [lists, vectors, sequences] when there can be duplicates. (common-elements [1] [1]) ; [1] (common-elements [1 2] [1 1]) ; [1] (common-elements [1 1] [1 1 1]) ; [1 1] Here is what I currently have: (defn remove-first [elem coll] (lazy-seq (when-let [s (seq coll)] (let [f (first s), r (rest s)] (if (= elem f) r (cons f (remove-first elem r))))))) (defn common-elements [coll1 coll2] (lazy-seq (when (and (seq coll1) (seq coll2)) (let [f (first coll1)] (if