C++ Solution


  • 0
    string findLongestWord(string s, vector<string>& d) {
            string res;
            int maxL= 0;
            sort(d.begin(), d.end());
            reverse(d.begin(), d.end());
            for(string word : d)
            {
                int i=0;
                for(auto c : s)
                    if(i<word.length() && word[i]==c) i++;
                if(i== word.length() && i >= maxL)
                {
                    res = word;
                    maxL = i;
                }
            }
            return res;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.