给出这样的平坦数据:
01001, Butter, salted
01002, Butter, whipped, with salt
01145, Butter, without salt
04601, Butter, light, stick, with salt
04602, Butter, light, stick, without salt
转换成这个的最佳方法是什么:
Butter (01001, 01002, 01145, 04601, 04602) -> salted (01001)
-> whipped (01002) -> with salt (01002)
-> without salt (01145)
-> light (04601, 04602) -> stick (04601, 04602) -> with salt (04601)
-> without salt (04602)
我首先考虑递归排序,但我意识到可能会有很多字符串比较效率。