当前位置:网站首页>LeetCode 3. 无重复字符的最长子串
LeetCode 3. 无重复字符的最长子串
2022-07-02 13:15:00 【_刘小雨】
给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。
示例 1:
输入: s = “abcabcbb”
输出: 3
解释: 因为无重复字符的最长子串是 “abc”,所以其长度为 3。
示例 2:
输入: s = “bbbbb”
输出: 1
解释: 因为无重复字符的最长子串是 “b”,所以其长度为 1。
示例 3:
输入: s = “pwwkew”
输出: 3
解释: 因为无重复字符的最长子串是 “wke”,所以其长度为 3。
请注意,你的答案必须是 子串 的长度,“pwke” 是一个子序列,不是子串。
class Solution {
public:
int lengthOfLongestSubstring(string s) {
unordered_map<char, int> hash;
int re = 0;
/// j 在后面,i在前面,从i和j之间找最长子串,当发现之间的字符数量>1 ,i需要向后移动
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;
}
};
边栏推荐
- Comprehensively interpret the background and concept of service mesh
- Vscade set multi line display of tab
- Multi data source configuration code
- Introduction to database system Chapter 1 short answer questions - how was the final exam?
- Trigger: MySQL implements adding or deleting a piece of data in one table and adding another table at the same time
- July 1st gift: Yi Jingjie's "hundred day battle" ended perfectly, and the database of Guiyang bank was sealed in advance
- 潘多拉 IOT 开发板学习(RT-Thread)—— 实验2 RGB LED 实验(学习笔记)
- 结构体的内存对齐
- Write your own CPU Chapter 11 - learning notes
- 自注意力机制和全连接的图卷积网络(GCN)有什么区别联系?
猜你喜欢
JS learning notes - first acquaintance
sql解决连续登录问题变形-节假日过滤
Summary | three coordinate systems in machine vision and their relationships
dried food! Understand the structural vulnerability of graph convolution networks
Mobile web development learning notes - Layout
What is the difference between self attention mechanism and fully connected graph convolution network (GCN)?
数据安全产业系列沙龙(三)| 数据安全产业标准体系建设主题沙龙
自注意力机制和全连接的图卷积网络(GCN)有什么区别联系?
Summary of monthly report | list of major events of moonbeam in June
After the win10 system is upgraded for a period of time, the memory occupation is too high
随机推荐
JS learning notes - operators
2022最新最详细必成功的在Vscode中设置背景图、同时解决不受支持的问题
mysql min() 求某条件下最小的值出现多个结果
Yyds dry goods inventory hands-on teaching you to carry out the packaging and release of mofish Library (fishing Library)
ROW_NUMBER()、RANK()、DENSE_RANK区别
IDEA中设置背景图片(超详细)
原神2.6服务端下载以及搭建安装教程
历史上的今天:支付宝推出条码支付;分时系统之父诞生;世界上第一支电视广告...
Some problems about MySQL installation
[fluent] dart data type number type (DART file creation | num type | int type | double type | num related API)
618 deep resumption: Haier Zhijia's winning methodology
Pandora IOT development board learning (RT thread) - Experiment 2 RGB LED experiment (learning notes)
Typescript array out of order output
SSM integration exception handler and project exception handling scheme
去除router-link中的下划线
Idea public method extraction shortcut key
外企高管、连续创业者、瑜伽和滑雪高手,持续迭代重构的程序人生
OSPF - route aggregation [(summary) including configuration commands] | address summary calculation method - detailed explanation
Understand the key technology of AGV -- the difference between laser slam and visual slam
Cloud native cicd framework: Tekton