问个算法题目
给一个字符串(无空格),一个字典,如果可以用字典单词分割字符串,就返回结果,返回任意一种结果即可,如果不存在,就返回空
例 字符串 “todayisaniceday”
字典 ["to","day","today","i","is","a","nice","day"]
返回 ["to day is a nice day"]
我用深度优先遍历,递归去做,但遇到点问题,有没有更好的算法呢?
例 字符串 “todayisaniceday”
字典 ["to","day","today","i","is","a","nice","day"]
返回 ["to day is a nice day"]
我用深度优先遍历,递归去做,但遇到点问题,有没有更好的算法呢?