当前位置:网站首页>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;
}
};
边栏推荐
- Convolution neural network -- convolution layer
- Dichotomy, discretization, etc
- Arduino 控制的 RGB LED 无限镜
- 网络工程师考核的一些常见的问题:WLAN、BGP、交换机
- 927. 三等分 模拟
- Records of some tools 2022
- One question per day 1447 Simplest fraction
- Règlement sur la sécurité des réseaux dans les écoles professionnelles secondaires du concours de compétences des écoles professionnelles de la province de Guizhou en 2022
- Educational Codeforces Round 116 (Rated for Div. 2) E. Arena
- 【Rust 笔记】17-并发(上)
猜你喜欢

【云原生】微服务之Feign自定义配置的记录

Navicat連接Oracle數據庫報錯ORA-28547或ORA-03135

LVS简介【暂未完成(半成品)】

Navicat连接Oracle数据库报错ORA-28547或ORA-03135

SQLMAP使用教程(二)实战技巧一

CF1637E Best Pair

传统数据库逐渐“难适应”,云原生数据库脱颖而出
![[article de jailhouse] jailhouse hypervisor](/img/f4/4809b236067d3007fa5835bbfe5f48.png)
[article de jailhouse] jailhouse hypervisor

Open source storage is so popular, why do we insist on self-development?

LaMDA 不可能觉醒吗?
随机推荐
leetcode-6110:网格图中递增路径的数目
[jailhouse article] performance measurements for hypervisors on embedded ARM processors
Control unit
【Rust 笔记】13-迭代器(下)
【Jailhouse 文章】Jailhouse Hypervisor
Daily question 2013 Detect square
【Rust 笔记】14-集合(下)
The difference between CPU core and logical processor
全排列的代码 (递归写法)
leetcode-3:无重复字符的最长子串
Binary search template
2022 极术通讯-Arm 虚拟硬件加速物联网软件开发
LeetCode 0108.将有序数组转换为二叉搜索树 - 数组中值为根,中值左右分别为左右子树
One question per day 1447 Simplest fraction
CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
2022 pole technology communication arm virtual hardware accelerates the development of Internet of things software
leetcode-6111:螺旋矩阵 IV
927. 三等分 模拟
Bit mask of bit operation
2022年貴州省職業院校技能大賽中職組網絡安全賽項規程