无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(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)所有單詞的子串的評論 (共 條)

分享到微博請遵守國家法律
瑞昌市| 思南县| 眉山市| 沭阳县| 吉安市| 怀化市| 胶州市| 含山县| 拜泉县| 育儿| 马尔康县| 汶川县| 怀集县| 横峰县| 锡林浩特市| 新野县| 黑山县| 竹北市| 陆河县| 临泽县| 开阳县| 京山县| 临猗县| 金沙县| 福安市| 安新县| 盐源县| 溧水县| 禄丰县| 沾化县| 孟村| 惠安县| 子洲县| 金门县| 婺源县| 尉氏县| 湘潭县| 正宁县| 思南县| 景东| 泉州市|