Construct a tree structure from list of string paths

后端 未结 6 781
名媛妹妹
名媛妹妹 2020-11-29 01:03

I have a collection of string paths like [\"x1/x2/x3\",\"x1/x2/x4\",\"x1/x5\"] in a list. I need to construct a tree-like structure from this list which can be iterated to g

6条回答
  •  眼角桃花
    2020-11-29 01:39

    Just split each path by its delimiter and then add them to a tree structure one by one.
    i.e. if 'x1' does not exist create this node, if it does exist go to it and check if there is a child 'x2' and so on...

提交回复
热议问题