55561bc4创建于 2022年12月27日历史提交
public class Solution
{
    public bool WordBreak(string s, IList<string> wordDict)
    {
        bool[] dp = new bool[s.Length + 1];
        Array.Fill(dp, false);
        dp[s.Length] = true;

        for (int i = s.Length - 1; i >= 0; i--)
        {
            foreach (var w in wordDict)
            {
                if (i + w.Length <= s.Length && s.Substring(i, w.Length) == w)
                    dp[i] = dp[i + w.Length];

                if (dp[i] == true)
                    break;
            }
        }
        return dp[0];
    }
}