当前位置:网站首页>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))
}
边栏推荐
- How can users create data tables on Web pages and store them in the database
- npm link的简单介绍及使用
- Yum install MySQL FAQ
- [C] Explain language file operation in detail
- (pc+wap) dream weaving template vegetable and fruit websites
- assert _Aligns
- Code dynamically controls textview to move right (not XML)
- Audio and video technology development weekly | 254
- Games101 review: shading, rendering pipelines
- Article setting top
猜你喜欢

MySQL(4)
![[steering wheel] tool improvement: common shortcut key set of sublime text 4](/img/51/fe95e95ccd5cd6406f3b49e3bdba3f.png)
[steering wheel] tool improvement: common shortcut key set of sublime text 4

【方向盘】启动命令和IDEA如何传递:VM参数、命令行参数、系统参数、环境变量参数、main方法参数

简单使用 MySQL 索引

AMD64 (x86_64) architecture ABI document:

ES6高级-利用原型对象继承方法

图像识别(七)| 池化层是什么?有什么作用?

I came to the library applet one click sign in and one click grab location tool

Prometheus + redis exporter + grafana monitor redis service

1.软件测试-----软件测试的基本概念
随机推荐
MySQL(4)
GAMES101复习:光栅化
Binary search 33. search rotation sort array
项目管理:精益管理法
如何有效的去防止别人穿该网站首页快照
[C] Explain language file operation in detail
Simply use MySQL index
I came to the library applet one click sign in and one click grab location tool
Stack Title: the longest absolute path of a file
Mandatory interview questions: 1. shallow copy and deep copy_ Deep copy
ES6高级-利用原型对象继承方法
Games101 review: shading, rendering pipelines
Basics - network and server
JS get the time composition array of two time periods
[C]详解语言文件操作
[steering wheel] use the 60 + shortcut keys of idea to share with you, in order to improve efficiency (live template & postfix completion)
[introduction to C language] zzulioj 1006-1010
Handling process of the problem that the virtual machine's intranet communication Ping fails
Study notes of pytorch deep learning practice: convolutional neural network (Advanced)
简单使用 MySQL 索引