当前位置:网站首页>The longest substring of sword finger offer without repeated characters
The longest substring of sword finger offer without repeated characters
2022-07-28 17:05:00 【Morita Rinko】
The longest substring without repeating characters
describe :
Please find the longest substring in the string that does not contain duplicate characters , Calculate the length of the longest substring .
Answer key :
Maintain a map Used to store the traversed characters and subscripts
maxlen Used to store the maximum length value
curlen Used to store the length of the non repeating string being traversed
There are three situations :
- The current character has not appeared , That is to say map There is no information about this character in , here curlen++
- The current character minus the subscript of the last occurrence of this character is greater than curlen, It indicates that the last time this character appeared, it was in the non repeating string of the previous calculation , That is, this character is not repeated ,curlen++
- The current character has appeared in the calculation of this non repeating string , The description has been repeated ,curlen=i-index
class Solution {
public:
/**
* The class name in the code 、 Method name 、 The parameter name has been specified , Do not modify , Return the value specified by the method directly
*
*
* @param s string character string
* @return int integer
*/
int lengthOfLongestSubstring(string s) {
// write code here
map<char, int> index;
int maxlen=0,curlen=0;
for(int i=0;i<s.length();i++){
if(index.find(s[i])==index.end()){
curlen++;
}else if(i-index[s[i]]>curlen){
curlen++;
}else{
curlen=i-index[s[i]];
}
if(curlen>maxlen){
maxlen=curlen;
}
// If it doesn't appear, it's to index Add elements to it , Once it appears, it is updated index value
index[s[i]]=i;
}
return maxlen;
}
};
边栏推荐
- 打造自组/安全/可控的LoRa网!Semtech首度回应“工信部新规”影响
- Re13:读论文 Gender and Racial Stereotype Detection in Legal Opinion Word Embeddings
- Question note 4 (the first wrong version, search the insertion position)
- 【从零开始学习SLAM】将坐标系变换关系发布到 topic tf
- RE14: reading paper illsi interpretable low resource legal decision making
- parseJson
- TCP handshake, waving, time wait connection reset and other records
- Re13: read the paper gender and racial stereotype detection in legal opinion word embeddings
- SUSE CEPH rapid deployment – storage6
- 阿里云-武林头条-建站小能手争霸赛
猜你喜欢

: No such file or directory

HTAP是有代价的

Ruoyi集成flyway后启动报错的解决方法

Re11:读论文 EPM Legal Judgment Prediction via Event Extraction with Constraints

Re13:读论文 Gender and Racial Stereotype Detection in Legal Opinion Word Embeddings

关于 CMS 垃圾回收器,你真的懂了吗?

【深度学习】:《PyTorch入门到项目实战》第四天:从0到1实现logistic回归(附源码)

技术分享 | 误删表以及表中数据,该如何恢复?
![[deep learning]: day 9 of pytorch introduction to project practice: dropout implementation (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 9 of pytorch introduction to project practice: dropout implementation (including source code)

MySQL 5.7 and sqlyogv12 installation and use cracking and common commands
随机推荐
Create a self-organizing / safe / controllable Lora network! Semtech responded for the first time to the impact of the "new regulations of the Ministry of industry and information technology"
SUSE CEPH add nodes, reduce nodes, delete OSD disks and other operations – storage6
概率论与数理统计第一章
Epoll horizontal departure, which edge triggers
Best cow fences solution
PHP calculate coordinate distance
How to set ticdc synchronization data to only synchronize the specified library?
How should I understand craft
Exercise note 5 (square of ordered array)
向高通支付18亿美元专利费之后,传华为向联发科订购了1.2亿颗芯片!官方回应
Mysql与Oracle的13点区别
做题笔记2(两数相加)
Call DLL file without source code
Leetcode9. Palindromes
PostgreSQL每周新闻—2022年7月20日
获取时间戳的三种方法的效率比较
关于 CMS 垃圾回收器,你真的懂了吗?
大学生参加六星教育PHP培训,找到了薪水远超同龄人的工作
Outline and principle of structured design -- modularization
关于Bug处理的一些看法