30_串联所有单词的子串

题目中没有说明,其实words中的单词都是等长的。
使用两个hashmap。对words中的每个word,用第一个map1储存单词出现次数,key为单词,value为出现次数;
对于string s,首先将其划分为words总长度的子串,然后对于这每一个子串,用第二个map2统计其中所有单词出现的次数,如果次数大于map1中的次数(对于map1中不存在的单词,map1[tempword]<map2[tempword]始终为真),则说明一定不匹配。

class Solution {
public:
	vector<int> findSubstring(string s, vector<string>& words) {	
		if (s.empty())
			return vector<int>();
		vector<int> res;
		int wordSumLen = words.size() * words[0].length();
		int singleLen = words[0].length();
		//统计words中每个word出现的个数
		map<string, int> map1;
		for (auto word : words)
		{
			if (map1.count(word) == 0)
			{
				map1.insert(pair<string, int>(word, 1));
			}
			else
				map1[word]++;
		}
		//wether the length of s is bigger than words
		if(s.length()< wordSumLen)
			return vector<int>();
		for (int i = 0; i <= (s.length() - wordSumLen); i++)
		{
			string subS;
			subS = s.substr(i, wordSumLen);
			map<string, int> map2;
			bool isMatch=1;
			for (int j = 0; j < wordSumLen; j = j + singleLen)
			{
				string tempword;
				tempword = subS.substr(j, singleLen);
				//add to hashtable
				if (map2.count(tempword) == 0)
				{
					map2.insert(pair<string, int>(tempword, 1));
				}
				else
					map2[tempword]++;
				if (map1[tempword] < map2[tempword])
				{
					isMatch = 0;
					break;
				}
			}
			if (isMatch)
				res.push_back(i);
		}
		return res;
	}
};
### 关于高级架构师试历真题下载 目前,关于高级架构师试的历真题获取方式主要依赖官方渠道或其他合法授权的学习平台。虽然无法直接提供具体的下载链接,但可以通过以下方法找到相关资源: #### 官方网站学习资料 中国计算机技术职业资格网(http://www.ruankao.org.cn/)是的官方网站,提供了大量权威的信息和部分免费样生练习[^1]。 #### 第三方教育机构 许多第三方教育培训机构会整理并发布历的模拟试以及解析文档。这些材料通常经过精心编撰,能够很好地覆盖试重点知识点,例如件架构风格、设计模式、件质量属性等内容[^2]。 #### 基于构件的开发实践 如果关注的是基于构件的件开发(CBSD),那么可以从实际案例出发研究如何利用商业现货产品(COTS)或者自定义构建模块来优化项目流程,这不仅有助于理解理论知识,在应对涉及此类主的实际操作型目时也大有裨益[^3]。 #### 质量属性分析实例 针对具体应用场景下的功能性和非功能性需求评估也是备过程中不可忽视的一环。比如在网络通信领域常见的Ping Echo请求响应机制对比心跳检测模式时所体现出来的效率差异等方面展开深入探讨就显得尤为重要[^4]。 以下是Python脚本用于自动化处理数据的一个简单例子: ```python def process_data(input_file, output_file): with open(input_file, 'r') as file_in: data = file_in.readlines() processed_data = [] for line in data: # 数据清洗逻辑 cleaned_line = clean_function(line) processed_data.append(cleaned_line) with open(output_file, 'w') as file_out: file_out.writelines(processed_data) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值