当前位置:网站首页>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;
}
};
边栏推荐
- Student course selection system (curriculum design of Shandong Agricultural University)
- Global and Chinese market of oil analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
- Remove the underline in router link
- 618深度複盤:海爾智家的制勝方法論
- Yyds dry inventory company stipulates that all interfaces use post requests. Why?
- [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
- 2022最新最详细必成功的在Vscode中设置背景图、同时解决不受支持的问题
- TCP server communication process (important)
- Seal Library - installation and introduction
- [fluent] dart data type boolean type (boolean type definition | logical operation)
猜你喜欢
Understand the key technology of AGV -- the difference between laser slam and visual slam
What if the win11 app store cannot load the page? Win11 store cannot load page
The light of ideal never dies
Bone conduction non ear Bluetooth headset brand, bone conduction Bluetooth headset brand recommendation
Yyds dry goods inventory student attendance system based on QT design
潘多拉 IOT 开发板学习(RT-Thread)—— 实验2 RGB LED 实验(学习笔记)
IDEA中设置背景图片(超详细)
What is normal distribution? What is the 28 law?
Sim2real environment configuration tutorial
Which software is good for machine vision?
随机推荐
(practice C language every day) the sum of the nearest three numbers
Yyds dry goods inventory # look up at the sky | talk about the way and principle of capturing packets on the mobile terminal and how to prevent mitm
Some problems about MySQL installation
Foreign enterprise executives, continuous entrepreneurs, yoga and skiing masters, and a program life of continuous iteration and reconstruction
Global and Chinese markets for carbon dioxide laser cutting heads 2022-2028: Research Report on technology, participants, trends, market size and share
Ranger (I) preliminary perception
虚假的暑假
学生选课系统(山东农业大学课程设计)
Unity Json 编写
PCL point cloud image transformation
Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus
Memory alignment of structure
触发器:Mysql实现一张表添加或删除一条数据,另一张表同时添加
电脑设备打印机驱动安装失败如何解决
Vscode设置标签页多行显示
分析超700万个研发需求发现,这8门编程语言才是行业最需要的!
Yyds dry goods inventory has not revealed the artifact? Valentine's Day is coming. Please send her a special gift~
JS learning notes - variables
Recalling the college entrance examination and becoming a programmer, do you regret it?
Mathematical analysis_ Notes_ Chapter 6: Riemann integral of univariate function