五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

leetcode c++ 串聯(lián)所有單詞的子串

2023-02-09 22:39 作者:神兮兮的喵社長  | 我要投稿

我的解:

時間擊敗了7.71%,內(nèi)存擊敗了18.3%(挺垃圾的)

#include <vector>

using namespace std;

class Solution {

public:

? ? vector<int> findSubstring(string s, vector<string>& words) {

? ? ? ? int len_w = words.back().length();

? ? ? ? int len_all = len_w * words.size();

? ? ? ? int len_s = s.length();


? ? ? ? vector<string> word;

? ? ? ? word.assign(words.begin(), words.end());

? ? ? ? std::sort(word.begin(), word.end());

? ? ? ? std::unique(word.begin(), word.end());


? ? ? ? vector<int> counts;

? ? ? ? for (int i =0;i<word.size();i++)

? ? ? ? {

? ? ? ? ? ? counts.push_back(std::count(words.begin(), words.end(), word.at(i)));

? ? ? ? }


? ? ? ? bool flag;

? ? ? ? vector<int> indexes;

? ? ? ? vector<string> temp;

? ? ? ? string str;

? ? ? ? for (int i=0; i<len_s && (len_s-i)>=len_all;i++)

? ? ? ? { ?

? ? ? ? ? ? flag = true;

? ? ? ? ? ? temp.clear();

? ? ? ? ? ? for(int j =0;j < words.size();j++)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? temp.push_back(s.substr(i+j*len_w,len_w));

? ? ? ? ? ? }


? ? ? ? ? ? for (int k =0;k<word.size();k++)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if(std::count(temp.begin(),temp.end(), word.at(k)) !=counts.at(k))

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? flag=false;

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }


? ? ? ? ? ? if (flag)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? indexes.push_back(i);

? ? ? ? ? ? }

? ? ? ? }


? ? ? ? return indexes;

? ? };

};



leetcode c++ 串聯(lián)所有單詞的子串的評論 (共 條)

分享到微博請遵守國家法律
香河县| 托克逊县| 苏尼特左旗| 沛县| 安乡县| 洛浦县| 应城市| 塘沽区| 新泰市| 华亭县| 阿拉善右旗| 桐梓县| 金昌市| 济南市| 内丘县| 武隆县| 盐山县| 灵山县| 滦南县| 广宁县| 酒泉市| 新巴尔虎左旗| 得荣县| 潢川县| 威远县| 隆昌县| 通化市| 蓬溪县| 射洪县| 兴和县| 藁城市| 葫芦岛市| 祁连县| 肥西县| 河池市| 阳江市| 东源县| 湘潭市| 齐河县| 额济纳旗| 五莲县|