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

时间: 2024-09-30 23:31:27

leetcode524的相关文章