当前位置:网站首页>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;
}
};
边栏推荐
- SSM integration exception handler and project exception handling scheme
- 路由模式:hash和history模式
- How to solve the failure of printer driver installation of computer equipment
- How to choose the right kubernetes storage plug-in? (09)
- Routing mode: hash and history mode
- Route service grid traffic through two-level gateway design
- Which software is good for machine vision?
- The difference and usage of calloc, malloc and realloc functions
- Leetcode -- number of palindromes
- 分析超700万个研发需求发现,这8门编程语言才是行业最需要的!
猜你喜欢

Headline | Asian control technology products are selected in the textile and clothing industry digital transformation solution key promotion directory of Textile Federation

Trigger: MySQL implements adding or deleting a piece of data in one table and adding another table at the same time

Analyzing more than 7million R & D needs, it is found that these eight programming languages are the most needed in the industry!

大厂面试总结大全

一文读懂AGV的关键技术——激光SLAM与视觉SLAM的区别

TCP拥塞控制详解 | 2. 背景

Seal Library - installation and introduction

Mobile web development learning notes - Layout

中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖

做机器视觉哪个软件好?
随机推荐
ROW_NUMBER()、RANK()、DENSE_RANK区别
Kubernetes family container housekeeper pod online Q & A?
总结|机器视觉中三大坐标系及其相互关系
AWS virtual machine expansion
Library management system (Shandong Agricultural University Curriculum Design)
Summary of monthly report | list of major events of moonbeam in June
Student course selection system (curriculum design of Shandong Agricultural University)
The median salary of TSMC's global employees is about 460000, and the CEO is about 8.99 million; Apple raised the price of iPhone in Japan; VIM 9.0 releases | geek headlines
大厂面试总结大全
What if the win11 app store cannot load the page? Win11 store cannot load page
sql解决连续登录问题变形-节假日过滤
Effectively use keywords to increase Amazon sales
Today in history: Alipay launched barcode payment; The father of time-sharing system was born; The first TV advertisement in the world
TCP拥塞控制详解 | 2. 背景
[North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array
Foreign enterprise executives, continuous entrepreneurs, yoga and skiing masters, and a program life of continuous iteration and reconstruction
Global and Chinese markets for slotting milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
Mobile web development learning notes - Layout
虚假的暑假
LeetCode 5. 最长回文子串