524 Longest Word in Dictionary through Deleting

Posted lina2014

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了524 Longest Word in Dictionary through Deleting相关的知识,希望对你有一定的参考价值。

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

C++:

class Solution {
public:
    string findLongestWord(string s, vector<string>& d) 
    {
        sort(d.begin(), d.end(), [](string a, string b){
            if (a.size() == b.size())
            {
                return a < b;
            }
            return a.size() > b.size();
        });
        for (string str : d)
        {
            int i = 0;
            for (char c : s) 
            {
                if (i < str.size() && c == str[i]) 
                {
                    ++i;
                }
            }
            if (i == str.size())
            {
                return str;
            }
        }
        return "";
    }
};

 参考:http://www.cnblogs.com/grandyang/p/6523344.html

以上是关于524 Longest Word in Dictionary through Deleting的主要内容,如果未能解决你的问题,请参考以下文章

524. Longest Word in Dictionary through Deleting

524 Longest Word in Dictionary through Deleting

[LeetCode] 524. Longest Word in Dictionary through Deleting

LeetCode 524. Longest Word in Dictionary through Deleting (通过删除字母匹配到字典里最长单词)

720. Longest Word in Dictionary

720. Longest Word in Dictionary