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

524 Longest Word in Dictionary through Deleting

时间:2018-04-22 21:43:12      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:turn   html   size   amp   public   for   .com   dict   problem   

详见: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

标签:turn   html   size   amp   public   for   .com   dict   problem   

原文地址:https://www.cnblogs.com/xidian2014/p/8909226.html

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