我有一个与此类似的树数据:
[0] =>
id = 5,
name = "TV",
parent_id = 1,
children =>
[0] =>
id = 6,
name = "PLASMA",
parent_id = 5,
children = null
[1] =>
id = 7,
name = "LCD",
parent_id = 5,
children =>
[0] =>
id = 8,
name = "Gloss",
parent_id = 7,
children = null
[1] =>
id = 9,
name = "Matte",
parent_id = 7,
children = null
[1] =>
id = 4,
name = "Printers",
parent_id = 1,
children =>
....
我有一个扁平的字符串数据,例如:
- 电视
- TV_PLASMA_光泽
- 电视_液晶
'_' 是子类别的分隔符。
查找类别 ID 数组的最佳算法是什么?
示例输入:
- 电视
- TV_PLASMA_光泽
- 电视_液晶
示例输出:
- 数组:5
- 数组:5、6、8
- 数组:5、7
语言无关紧要——它只是一种算法——但在这种情况下,我更喜欢 C#。
谢谢你。