当前位置:网站首页>Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters
2022-07-26 02:44:00 【Husins】
Title Description
Given a string s, find the length of the longest substring without repeating characters.
Example 1:
Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example 2:
Input: s = "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.
Example 3:
Input: s = "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
Topic analysis
No repeat longest string , The dictionary can be used to judge whether there are duplicate values , From the first , Move to the right first , Until a duplicate character appears , Now move the left , Until repeated characters are excluded , Continue to move the right , Record every time result Value , Retain the maximum value .
func lengthOfLongestSubstring(s string) int {
if len(s) == 0 {
return 0
}
var bitSet [256]bool
result, left, right := 0, 0, 0
for left < len(s) {
if bitSet[s[right]] {
bitSet[s[left]] = false
left++
} else {
bitSet[s[right]] = true
right++
}
if result < right-left {
result = right - left
}
if left+result >= len(s) || right >= len(s) {
break
}
}
return result
}
func main() {
s := "aabbccddabcde"
fmt.Println(lengthOfLongestSubstring(s))
}
边栏推荐
- Yum install MySQL FAQ
- (Dynamic Programming Series) sword finger offer 48. the longest substring without repeated characters
- SQL how to return all data when the input query condition is empty
- Keil's operation before programming with C language
- 流形学习、、
- assert _ Aligns
- U++ print information to screen and log
- [pure theory] Yolo v4: optimal speed and accuracy of object detection
- scipy.sparse.vstack
- 栈题目:文件的最长绝对路径
猜你喜欢

What can EAM system help enterprises do?

案例:使用keepalived+Haproxy搭建Web群集

Simply use MySQL index

ES6 advanced - inherit parent class attributes with constructors

How to effectively prevent others from wearing the homepage snapshot of the website

HLS实验一--乘法器

C unit test
![[steering wheel] use the 60 + shortcut keys of idea to share with you, in order to improve efficiency (reconstruction)](/img/b4/62a4c06743fdedacdffd9b156a760f.png)
[steering wheel] use the 60 + shortcut keys of idea to share with you, in order to improve efficiency (reconstruction)
![[C]详解语言文件操作](/img/12/4affa1d3fb3e4ee126e1c1e3872d9b.png)
[C]详解语言文件操作

第3章业务功能开发(删除线索)
随机推荐
Exclusive interview with ringcentral he Bicang: empowering future mixed office with innovative MVP
Bo Yun container cloud and Devops platform won the trusted cloud "technology best practice Award"
VOFA+ 串口调试助手
Brief introduction and use of NPM link
IDEA运行web项目出现乱码问题有效解决(附详细步骤)
Image recognition (VII) | what is the pooling layer? What's the effect?
Li Kou 148: sorting linked list
信息系统项目管理师必背核心考点(五十)合同内容约定不明确规定
Study notes of pytorch deep learning practice: convolutional neural network (Advanced)
Annotation development
HLS Experiment 1 -- multiplier
Prometheus + redis exporter + grafana monitor redis service
Wechat applet - get user location (longitude and latitude + city)
Is the securities account presented by qiniu true? How to open it safely and reliably?
简单使用 MySQL 索引
020-024 polymorphism review
MySQL教程:MySQL数据库学习宝典(从入门到精通)
GAMES101复习:着色(Shading)、渲染管线
图像识别(六)| 激活函数
Extended Physics-InformedNeural Networks论文详解