当前位置:网站首页>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;
}
};
边栏推荐
- Bone conduction non ear Bluetooth headset brand, bone conduction Bluetooth headset brand recommendation
- How to choose the right kubernetes storage plug-in? (09)
- Leetcode -- number of palindromes
- LeetCode 1. 两数之和
- 618 reprise en profondeur: la méthode gagnante de la famille Haier Zhi
- 618深度複盤:海爾智家的制勝方法論
- Vscode设置标签页多行显示
- Where can I open computer administrator permissions
- What is normal distribution? What is the 28 law?
- 月报总结|Moonbeam6月份大事一览
猜你喜欢

渗透工具-内网权限维持-Cobalt strike

做机器视觉哪个软件好?

隐私计算技术创新及产业实践研讨会:学习

曆史上的今天:支付寶推出條碼支付;分時系統之父誕生;世界上第一支電視廣告...

Seal Library - installation and introduction

unity Hub 登录框变得很窄 无法登录

七一献礼:易鲸捷 “百日会战”完美收官 贵阳银行数据库提前封板

Yyds dry goods inventory has not revealed the artifact? Valentine's Day is coming. Please send her a special gift~

unity Hub 登錄框變得很窄 無法登錄
![[fluent] dart data type string type (string definition | string splicing | string API call)](/img/7b/cc624aa33f45fbed0bbe354253158b.jpg)
[fluent] dart data type string type (string definition | string splicing | string API call)
随机推荐
Trigger: MySQL implements adding or deleting a piece of data in one table and adding another table at the same time
Kubernetes family container housekeeper pod online Q & A?
触发器:Mysql实现一张表添加或删除一条数据,另一张表同时添加
隐私计算技术创新及产业实践研讨会:学习
Yyds dry inventory uses thread safe two-way linked list to realize simple LRU cache simulation
Student course selection system (curriculum design of Shandong Agricultural University)
虚假的暑假
SSM integration exception handler and project exception handling scheme
PCL least median square method fitting plane
Leetcode -- number of palindromes
LeetCode 4. 寻找两个正序数组的中位数(hard)
mysql min() 求某条件下最小的值出现多个结果
Yyds dry inventory company stipulates that all interfaces use post requests. Why?
Route service grid traffic through two-level gateway design
HMS core machine learning service helps zaful users to shop conveniently
Global and Chinese markets of stainless steel surgical suture 2022-2028: Research Report on technology, participants, trends, market size and share
Some problems about MySQL installation
Headline | Asian control technology products are selected in the textile and clothing industry digital transformation solution key promotion directory of Textile Federation
unity Hub 登錄框變得很窄 無法登錄
[error record] the connection of the flutter device shows loading (disconnect | delete the shuttle/bin/cache/lockfile file)