当前位置:网站首页>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))
}
边栏推荐
- 如何有效的去防止别人穿该网站首页快照
- GAMES101复习:光栅化
- C language -- program environment and preprocessing
- IDEA运行web项目出现乱码问题有效解决(附详细步骤)
- 记录之目标检测NMS(非极大值抑制)
- 关于mysql的问题,希望个位能帮一下忙
- U++ common type conversion and common forms and proxies of lambda
- Recorded target detection NMS (non maximum suppression)
- 1. Software testing ----- the basic concept of software testing
- Prometheus + redis exporter + grafana monitor redis service
猜你喜欢

Extended Physics-InformedNeural Networks论文详解

AMD64 (x86_64) architecture ABI document:

Information System Project Manager - Chapter 10 communication management and stakeholder management examination questions over the years

Project management: lean management method

循环与分支(一)

基础知识-网络与服务器

HLS实验一--乘法器

信息系统项目管理师---第十章沟通管理和干系人管理历年考题

Adruino basic experimental learning (I)

Literature speed reading | in the face of danger, anxious people run faster?
随机推荐
IDEA运行web项目出现乱码问题有效解决(附详细步骤)
18_ Request file
Project management: lean management method
Prometheus + redis exporter + grafana monitor redis service
AMD64(x86_64)架构abi文档:中
Pipnet: face key point detection for natural scenes "pixel in pixel net: directions efficient facial landmark detection in the wild"
U++ common type conversion and common forms and proxies of lambda
获取时分秒
信息系统项目管理师---第十章沟通管理和干系人管理历年考题
必会面试题:1.浅拷贝和深拷贝_深拷贝
Brief introduction and use of NPM link
MySQL build websites data table
How to speed up matrix multiplication
Effectively solve the problem of garbled code when idea runs the web project (with detailed steps)
Games101 review: rasterization
织梦提示你设定了字段为联动类型如何解决
Wechat official account mutual aid, open white groups, and small white newspaper groups to keep warm
Get hours, minutes and seconds
流形学习、、
Prometheus + process exporter + grafana monitor the resource usage of the process