1 Star 0 Fork 0

Paulden/Algorithm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
longest_sub_string.go 390 Bytes
一键复制 编辑 原始数据 按行查看 历史
Paulden 提交于 2022-09-06 20:23 . implement max sliding window
package string
// Problem Definition: https://leetcode.cn/problems/longest-substring-without-repeating-characters/
func lengthOfLongestSubstring(s string) int {
hash := make(map[byte]int)
var ret int
left, right := 0, 0
for right < len(s) {
b := s[right]
hash[b]++
right += 1
for hash[b] > 1 {
hash[s[left]]--
left++
}
ret = max(ret, right-left)
}
return ret
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/guuzaa/algorithm.git
git@gitee.com:guuzaa/algorithm.git
guuzaa
algorithm
Algorithm
main

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385