当前位置:网站首页>2022.5.25-----leetcode.467
2022.5.25-----leetcode.467
2022-06-09 12:28:00 【路Lu727】
public int findSubstringInWraproundString(String p) {
int n=p.length();
char[] chs=p.toCharArray();
int[] dp=new int[26];//存储以某字母为结束的子串最大长度,同时表示该子串的以该字母结束的子串数量
dp[chs[0]-'a']=1;
int len=1;
for(int i=1;i<n;i++){
//更新以当前字母结尾的满足条件的最大长度
if((chs[i]-chs[i-1]+26)%26==1){
len++;
}else{
len=1;
}
//每次更新,如果当前长度大于已有长度,那么以该字母为结束的子串的子串集合(同样以该字母结束)一定包含之前的集合,从而去重
dp[chs[i]-'a']=Math.max(dp[chs[i]-'a'],len);
}
return Arrays.stream(dp).sum();
}边栏推荐
- U8g2 graphics library and STM32 migration (I2C, software and hardware)
- 【C语言练习——调整数组内奇数偶数的顺序】
- Achieve ceiling effect in wechat applet (smooth and not stuck)
- 面试题 08.07. 无重复字符串的排列组合
- 机器学习-学习笔记(二) --&gt; 模型评估与选择
- 软件测试工程师手把手教你如何制定测试计划
- Database day-6
- 射频同轴连接器和电缆指南--【转自微信公众号射频课堂】
- Differences between AVR and arm and common Arduino
- Method area of JVM runtime memory area family
猜你喜欢
随机推荐
U8g2图形库与STM32移植(I2C,软件与硬件)
【C语言练习——打印菱形及其变形】
Development and present situation of Network Space Surveying and mapping at home and abroad
wsl2环境搭建
JVM运行时内存区系列之方法区
云呐|公司实物资产如何管理
面试题 08.08. 有重复字符串的排列组合
Yunna RFID asset management, advantages of RFID asset management system
BI报表系统有什么特点
使用nodejs导出md/Markdown文档当中的图片到本地并替换原始图片链接为本地图片链接
网络空间测绘国内外发展及现状
数字化转型:如何获得组织的认可?
数据库day-3
C language queue -- chain queue
记一次程序内存占用高问题排查
Comment résoudre le problème du réseau d'entreprise en accélérant la fusion du réseau Cloud pour le troisième anniversaire de la licence 5G?
curl post请求携带请求头,传递接送参数数据的命令
面试题 05.06. 整数转换
C language queue -- sequential queue
fastapi基于pytest的异步测试(tortoise-orm)









