当前位置:网站首页>Leetcode-3: Longest substring without repeated characters
Leetcode-3: Longest substring without repeated characters
2022-07-05 06:09:00 【Chrysanthemum headed bat】
leetcode-3: Longest substring without repeating characters
subject
Topic linking
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 .
Problem solving
Method 1 : Sliding window and hash collection
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int res=INT_MIN;
unordered_set<char> set;
int left=0,right=0;
while(right<s.size()){
if(set.count(s[right])==0){
set.insert(s[right]);
right++;
}
else{
set.erase(s[left]);
left++;
}
res=max(res,right-left);
}
if(res==INT_MIN) return 0;
else return res;
}
};
边栏推荐
- Fried chicken nuggets and fifa22
- Open source storage is so popular, why do we insist on self-development?
- Navicat連接Oracle數據庫報錯ORA-28547或ORA-03135
- 2020ccpc Qinhuangdao J - Kingdom's power
- 实时时钟 (RTC)
- Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
- Time of process
- 【Jailhouse 文章】Jailhouse Hypervisor
- [rust notes] 14 set (Part 2)
- Over fitting and regularization
猜你喜欢

中职网络安全技能竞赛——广西区赛中间件渗透测试教程文章

Introduction and experience of wazuh open source host security solution

实时时钟 (RTC)

Data visualization chart summary (I)

LaMDA 不可能觉醒吗?

Spark中groupByKey() 和 reduceByKey() 和combineByKey()

MatrixDB v4.5.0 重磅发布,全新推出 MARS2 存储引擎!

数据可视化图表总结(二)
![R language [import and export of dataset]](/img/5e/a15ab692a6f049f846024c98820fbb.png)
R language [import and export of dataset]

Educational Codeforces Round 116 (Rated for Div. 2) E. Arena
随机推荐
开源存储这么香,为何我们还要坚持自研?
一些工具的记录2022
6. Logistic model
Full Permutation Code (recursive writing)
Wazuh開源主機安全解决方案的簡介與使用體驗
Over fitting and regularization
Implement a fixed capacity stack
The difference between CPU core and logical processor
Simply sort out the types of sockets
数据可视化图表总结(二)
CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
F - Two Exam(AtCoder Beginner Contest 238)
884. Uncommon words in two sentences
1041 Be Unique
Simple knapsack, queue and stack with deque
剑指 Offer II 058:日程表
[rust notes] 14 set (Part 2)
redis发布订阅命令行实现
【云原生】微服务之Feign自定义配置的记录
Navicat連接Oracle數據庫報錯ORA-28547或ORA-03135