当前位置:网站首页>2022.6.23-----leetcode.30
2022.6.23-----leetcode.30
2022-06-26 03:16:00 【路Lu727】
public List<Integer> findSubstring(String s, String[] words) {
int len=s.length();
int m=words[0].length();
int n= words.length;
Map<String,Integer> map=new HashMap<>();//存储单词及其数量
List<Integer> ans=new ArrayList<>();
for(String word:words){
map.put(word,map.getOrDefault(word,0)+1);
}
//枚举m*n长度的子串,起点由[0,m-1],每个起点的右移步长为m
for (int i = 0; i <m; i++) {
Map<String, Integer> map1=new HashMap<>();//存储子串的单词
//记录初始单词
for (int j = i; j +m<=Math.min(len,i+m*n) ; j+=m) {
String tmp=s.substring(j,j+m);
map1.put(tmp,map1.getOrDefault(tmp,0)+1);
}
if(map1.equals(map)) ans.add(i);
String l="";
String r="";
//每次右移,添加新单词,去掉旧单词
for (int j = i; j +m*n+m<=len ; j+=m) {
l=s.substring(j,j+m);
r=s.substring(j+m*n,j+m*n+m);
if(map1.get(l)==1) map1.remove(l);
else map1.put(l,map1.get(l)-1);
map1.put(r,map1.getOrDefault(r,0)+1);
if(map1.equals(map)) ans.add(j+m);
}
}
return ans;
}边栏推荐
- 数字孪生智慧水务,突破海绵城市发展困境
- Cultivate children's creativity under the concept of project steam Education
- mysql存儲過程
- Sqlitestudio download address
- Problems encountered in project deployment - production environment
- 云计算基础-0
- MySQL development environment
- 少儿编程对国内传统学科的推进作用
- Popupwindow utility class
- jupyter notebook的插件安装以及快捷键
猜你喜欢

Classic model - Nin & googlenet
![[reading papers] fbnetv3: joint architecture recipe search using predictor training network structure and super parameters are all trained by training parameters](/img/84/2b66b513a0a36464233708fbb4b57d.png)
[reading papers] fbnetv3: joint architecture recipe search using predictor training network structure and super parameters are all trained by training parameters

“再谈”协议

解析创客空间机制建设的多样化

解析社交机器人中的技术变革
![[paper notes] supersizing self supervision: learning to grasp from 50K tries and 700 robot hours](/img/fe/f8208747e03133f4a66e73598409d5.png)
[paper notes] supersizing self supervision: learning to grasp from 50K tries and 700 robot hours

用元分析法驱动教育机器人的发展

Analysis of the multiple evaluation system of children's programming

Add an "open search description" to the site to adapt to the browser's "site search"“

丝网印刷的种类及其应用方法
随机推荐
Vulhub replicate an ActiveMQ
Nebula Graph学习篇3_多线程完成6000w+关系数据迁移
【哈希表】改进,拉链法哈希结构——直接用两个索引查找,不用每次都hash和%一遍
云计算基础-0
2022年挖财证券开户安全嘛?
[system architecture] - how to evaluate software architecture
Andorid hide the title bar of the system
Xgboost, lightgbm, catboost -- try to stand on the shoulders of giants
Tupu software is the digital twin of offshore wind power, striving to be the first
MySQL stored procedure
Redux thunk simple case, advantages, disadvantages and thinking
Procédures stockées MySQL
进度条
usb peripheral 驱动 - 枚举
Kotlin quick start
Android gap animation translate, scale, alpha, rotate
Preparation for wechat applet development
MySQL高级部分( 四: 锁机制、SQL优化 )
HL7Exception: Can‘t XML-encode a GenericMessage. Message must have a recognized struct
mysql存儲過程