SP5. 牛客代码自动补全
描述
示例1
输入:
["Niu Niu","Niu Mei","Niu Neng","Nowcoder"],["Niu", "Now"]
输出:
[["Niu Niu","Niu Mei","Niu Neng"],["Nowcoder"]]
C++ 解法, 执行用时: 3ms, 内存消耗: 412KB, 提交时间: 2022-07-25
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param dict string字符串vector * @param strings string字符串vector * @return string字符串vector<vector<>> */ vector<vector<string> > typeahead(vector<string>& dict, vector<string>& strings) { // write code here vector<vector<string>> res{}; if(dict.size() == 0 || strings.size() == 0) return res; for(int i=0;i<strings.size();i++) { vector<string> arr; for(int j=0;j<dict.size();j++) { if(dict[j].find(strings[i]) != string::npos) { arr.push_back(dict[j]); } } res.push_back(arr); } return res; } };
C++ 解法, 执行用时: 3ms, 内存消耗: 420KB, 提交时间: 2022-08-06
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param dict string字符串vector * @param strings string字符串vector * @return string字符串vector<vector<>> */ vector<vector<string> > typeahead(vector<string>& dict, vector<string>& strings) { // write code here vector<vector<string>> res{}; if(dict.size()==0||strings.size()==0) return res; for(int i=0;i<strings.size();i++) { vector<string> arr; for(int j=0;j<dict.size();j++) { if(dict[j].find(strings[i])!=string::npos) { arr.push_back(dict[j]); } } res.push_back(arr); } return res; } };
C++ 解法, 执行用时: 3ms, 内存消耗: 420KB, 提交时间: 2022-07-26
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param dict string字符串vector * @param strings string字符串vector * @return string字符串vector<vector<>> */ vector<vector<string> > typeahead(vector<string>& dict, vector<string>& strings) { // write code here vector<vector<string>> res{}; if(dict.size() == 0 || strings.size() == 0) return res; for(int i=0;i<strings.size();i++) { vector<string> arr; for(int j=0;j<dict.size();j++) { if(dict[j].find(strings[i]) != string::npos) { arr.push_back(dict[j]); } } res.push_back(arr); } return res; } };
C++ 解法, 执行用时: 3ms, 内存消耗: 424KB, 提交时间: 2022-07-25
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param dict string字符串vector * @param strings string字符串vector * @return string字符串vector<vector<>> */ vector<vector<string> > typeahead(vector<string>& dict, vector<string>& strings) { // write code here vector<vector<string>> res; for(auto& str:strings) { vector<string> temp; for(auto& v:dict) { if(v.find(str)!=string::npos) temp.push_back(v); } res.push_back(temp); } return res; } };
C++ 解法, 执行用时: 3ms, 内存消耗: 424KB, 提交时间: 2022-07-19
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param dict string字符串vector * @param strings string字符串vector * @return string字符串vector<vector<>> */ vector<vector<string> > typeahead(vector<string>& dict, vector<string>& strings) { // write code here vector<vector<string>> res; for(auto& str : strings){ vector<string> temp; for(auto& v : dict){ if(v.find(str) != string::npos){ temp.push_back(v); } } res.push_back(temp); } return res; } };