Clojure: How to generate a 'trie'?

前端 未结 4 1129
死守一世寂寞
死守一世寂寞 2021-02-08 00:19

Given the following...

(def inTree
 \'((1 2)
   (1 2 3)
   (1 2 4 5 9)
   (1 2 4 10 15)
   (1 2 4 20 25)))

How would you transform it to this t

4条回答
  •  时光说笑
    2021-02-08 00:33

    As a general approach, here's what I would do:

    • Write a few functions to create a trie and to insert new elements into a trie.
    • Create a new trie.
    • Iterate through the input list and insert each element into the trie.

    This problem lends itself very well to a recursive implementation. I would aim for that if possible.

提交回复
热议问题