码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode524

时间:2017-06-04 10:43:33      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:tar   ref   str   through   http   lis   ring   cti   span   

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

标签:tar   ref   str   through   http   lis   ring   cti   span   

原文地址:http://www.cnblogs.com/asenyang/p/6939632.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!