当前位置:网站首页>Force deduction solution summary 467- unique substring in surrounding string
Force deduction solution summary 467- unique substring in surrounding string
2022-06-12 02:08:00 【Lost summer】
Directory links :
Force buckle programming problem - The solution sums up _ Share + Record -CSDN Blog
GitHub Synchronous question brushing items :
https://github.com/September26/java-algorithms
Original link :
describe :
Put the string s See as “abcdefghijklmnopqrstuvwxyz” Infinite wrapping string of , therefore s It looks like this :
"...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd...." .
Now give another string p . return s in only Of p Of Non empty substring The number of .
Example 1:
Input : p = "a"
Output : 1
explain : character string s Only one of them "a" Sub character .
Example 2:
Input : p = "cac"
Output : 2
explain : character string s String in “cac” Only two substrings “a”、“c”..
Example 3:
Input : p = "zab"
Output : 6
explain : In string s There are six substrings in “z”、“a”、“b”、“za”、“ab”、“zab”.
Tips :
1 <= p.length <= 105
p Composed of lowercase English letters
source : Power button (LeetCode)
link :https://leetcode.cn/problems/unique-substrings-in-wraparound-string
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Their thinking :
* Their thinking : * The core is to find the string beginning with a certain letter , What is the longest length . The short one must be a long substring .
Code :
public class Solution467 {
public int findSubstringInWraproundString(String p) {
int[] dp = new int[26];
int k = 0;
for (int i = 0; i < p.length(); ++i) {
if (i > 0 && (p.charAt(i) - p.charAt(i - 1) + 26) % 26 == 1) { // The difference between characters is 1 or -25
++k;
} else {
k = 1;
}
dp[p.charAt(i) - 'a'] = Math.max(dp[p.charAt(i) - 'a'], k);
}
return Arrays.stream(dp).sum();
}
}边栏推荐
- ACL2022 | DCSR:一种面向开放域段落检索的句子感知的对比学习方法
- 力扣解法汇总467-环绕字符串中唯一的子字符串
- PHP security development 13 column module of blog system
- Modification of system module information of PHP security development 12 blog system
- Niuke monthly race 14- simple counting
- 如何定位关键词使得广告精准投放。
- How to improve the advertising rating of advertising, that is, the quality score?
- Xcall cluster script (view JPS command)
- Installing mysql-5.7 for Linux (centos7)
- What are the preparations for setting up Google search advertising series?
猜你喜欢

Graphic data analysis | business cognition and data exploration

消防栓监测系统毕业设计---论文(附加最全面的从硬件电路设计->驱动程序设计->阿里云物联网搭建->安卓APP设计)

Ozzanation - système d'action basé sur sse

MySQL高级部分知识点

Don't miss it! Five large data visualization screens that HR must collect

Linux(CentOS6)安装MySQL5.5版本数据库

入手Ticwatch2

Installing MySQL version 5.5 database for Linux (centos6)

How WPS inserts a directory and the operating steps for quickly inserting a directory

How should programmers solve the problem of buying vegetables? Take you hand in hand to quickly order and grab vegetables by using the barrier free auxiliary function
随机推荐
Linux(CentOS6)安装MySQL5.5版本数据库
如何定位关键词使得广告精准投放。
A mystery of the end of vagrant up
matplotlib. pyplot. Bar chart (II)
php开发 博客系统的公告模块的建立和引入
"China Dongxin Cup" the fourth programming competition of Guangxi University (synchronous competition)
Design principle [Demeter's Law]
RPA introduction
Force deduction solution summary 1728- cat and mouse II
Add sequence number column to MySQL query result set
如何提高广告的广告评级,也就是质量得分?
阿里云oss文件上传系统
广泛匹配修饰符符号已经被弃用,请勿使用
通用树形结构的迭代与组合模式实现方案
How to locate keywords to make advertising accurate.
Almost all schools will ask for the second round exam! Come in and recite the answer!
SwiftyJSON解析本地JSON文件
混泥土(地面+墙面)+ 山体裂缝数据集汇总(分类及目标检测)
力扣解法汇总449-序列化和反序列化二叉搜索树
Explore performance optimization! Performance improvement from 2 months to 4 hours!