当前位置:网站首页>LeetCode 3. Longest substring without duplicate characters
LeetCode 3. Longest substring without duplicate characters
2022-07-02 16:40:00 【_ Liu Xiaoyu】
Given a string s , Please find out that there are no duplicate characters in it Longest substrings The length of .
Example 1:
Input : s = “abcabcbb”
Output : 3
explain : Because the longest substring without repeating characters is “abc”, So its length is 3.
Example 2:
Input : s = “bbbbb”
Output : 1
explain : Because the longest substring without repeating characters is “b”, So its length is 1.
Example 3:
Input : s = “pwwkew”
Output : 3
explain : Because the longest substring without repeating characters is “wke”, So its length is 3.
Please note that , Your answer must be Substring The length of ,“pwke” Is a subsequence , Not substring .
class Solution {
public:
int lengthOfLongestSubstring(string s) {
unordered_map<char, int> hash;
int re = 0;
/// j rearwards ,i in front , from i and j Find the longest substring between , When finding the number of characters between >1 ,i Need to move back
for(int i = 0, j = 0; j < s.size(); j++)
{
hash[s[j]] ++;
while(hash[s[j]] > 1) hash[s[i++]] --;
re = max(re, j- i + 1);
}
return re;
}
};
边栏推荐
- 忆当年高考|成为程序员的你,后悔了吗?
- ROW_ NUMBER()、RANK()、DENSE_ Rank difference
- Yyds dry goods inventory # look up at the sky | talk about the way and principle of capturing packets on the mobile terminal and how to prevent mitm
- 中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
- 电脑设备打印机驱动安装失败如何解决
- TCP拥塞控制详解 | 2. 背景
- Yyds dry inventory method of deleting expired documents in batch
- Which software is good for machine vision?
- Yyds dry goods inventory has not revealed the artifact? Valentine's Day is coming. Please send her a special gift~
- How to use stustr function in Oracle view
猜你喜欢
自注意力机制和全连接的图卷积网络(GCN)有什么区别联系?
请问怎么在oracle视图中使用stustr函数
Text intelligent expansion and contraction control of swiftui text component (tutorial includes source code)
Summary of monthly report | list of major events of moonbeam in June
去除router-link中的下划线
流批一体在京东的探索与实践
理想之光不灭
IDEA中设置背景图片(超详细)
做机器视觉哪个软件好?
What is normal distribution? What is the 28 law?
随机推荐
Unity Json 编写
The light of ideal never dies
Global and Chinese markets for carbon dioxide laser cutting heads 2022-2028: Research Report on technology, participants, trends, market size and share
618 deep resumption: Haier Zhijia's winning methodology
Take you ten days to easily complete the go micro service series (I)
Thinking about absolute truth and relative truth
SQL solves the problem of continuous login deformation holiday filtering
La boîte de connexion du hub de l'unit é devient trop étroite pour se connecter
电脑管理员权限在哪里可以打开
Global and Chinese markets for disposable insulin pumps 2022-2028: Research Report on technology, participants, trends, market size and share
How to use stustr function in Oracle view
PyC file decompile
总结|机器视觉中三大坐标系及其相互关系
LeetCode 3. 无重复字符的最长子串
路由模式:hash和history模式
What is the difference between self attention mechanism and fully connected graph convolution network (GCN)?
Mysql database mysqldump why there is no statement to create a database
The login box of unity hub becomes too narrow to log in
Mobile web development learning notes - Layout
Yyds dry inventory executor package (parameter processing function)