/* * ========================================================================= * * FileName: leetcode_748.cpp * * Description: * * Version: 1.0 * Created: 2018-11-29 09:49:04 * Last Modified: 2018-11-29 09:49:25 * Revision: none * Compiler: gcc * * Author: zt () * Organization: * * ========================================================================= */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; string shortestCompletingWord ( string licensePlate, vector& words ) { string lic; vector vs; vs.reserve ( 1000 ); for ( auto& c : licensePlate ) if ( isalpha ( c ) ) lic.push_back ( tolower ( c ) ); auto f = [&] ( string s ) { size_t pos; for ( auto& c : lic ) { pos = s.find ( c ); if ( pos == string::npos ) return false; else s[pos] = '0'; } return true; }; for ( auto& s : words ) if ( f ( s ) ) vs.push_back ( s ); stable_sort ( vs.begin(), vs.end(), [] ( string s1, string s2 ) { return s1.size() < s2.size(); } ); return vs.front(); } int main ( int argc, char* argv[] ) { ( void ) argc; ( void ) argv; return 0; }