首页 > 代码库 > leetcode524

leetcode524

public class Solution {
    public string FindLongestWord(string s, IList<string> d) {
        string longest = "";
            foreach (var dictWord in d)
            {
                int i = 0;
                foreach (var c in s)
                {
                    if (i < dictWord.Length && c == dictWord[i])
                    {
                        i++;
                    }
                }

                if (i == dictWord.Length && dictWord.Length >= longest.Length)
                {
                    if (dictWord.Length > longest.Length || dictWord.CompareTo(longest) < 0)
                    {
                        longest = dictWord;
                    }
                }
            }
            return longest;
    }
}

https://leetcode.com/problems/longest-word-in-dictionary-through-deleting/#/description

leetcode524