当前位置:网站首页>Leecode3. Longest substring without repeated characters
Leecode3. Longest substring without repeated characters
2022-07-07 13:33:00 【Miaomiao boss】
class Solution:
def lengthOfLongestSubstring(s: str) -> int:
# Hash set , Record whether each character appears
occ = set()
n = len(s)
# Right pointer , The initial value is -1, It's like we're on the left side of the left bound of the string , It's not moving yet
rk, ans = -1, 0
for i in range(n):
if i != 0:
# The left pointer moves one space to the right , Remove a character
occ.remove(s[i - 1])
while rk + 1 < n and s[rk + 1] not in occ:
# Keep moving the right pointer
occ.add(s[rk + 1])
rk += 1
# The first i To rk A character is a very long non repeating character substring
ans = max(ans, rk - i + 1)
print(ans)
s=Solution.lengthOfLongestSubstring("pwwkew")
边栏推荐
猜你喜欢
最佳实践 | 用腾讯云AI意愿核身为电话合规保驾护航
Esp32 construction engineering add components
Vscade editor esp32 header file wavy line does not jump completely solved
Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)
Cinnamon taskbar speed
OSI 七层模型
2022-7-7 Leetcode 34.在排序数组中查找元素的第一个和最后一个位置
【黑马早报】华为辟谣“军师”陈春花;恒驰5预售价17.9万元;周杰伦新专辑MV 3小时播放量破亿;法华寺回应万元月薪招人...
Milkdown 控件图标
室内ROS机器人导航调试记录(膨胀半径的选取经验)
随机推荐
Summary of import, export, backup and recovery of mongodb
xshell连接服务器把密钥登陆改为密码登陆
Toraw and markraw
Ogre introduction
Japanese government and enterprise employees got drunk and lost 460000 information USB flash drives. They publicly apologized and disclosed password rules
Milkdown 控件图标
648. 单词替换 : 字典树的经典运用
Thread pool reject policy best practices
Digital IC Design SPI
Realize the IP address home display function and number home query
Esp32 ① compilation environment
Clion mingw64 Chinese garbled code
Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)
Introduction and basic use of stored procedures
MongoDB复制(副本集)总结
Why can basic data types call methods in JS
2022-7-6 使用SIGURG来接受外带数据,不知道为什么打印不出来
实现IP地址归属地显示功能、号码归属地查询
shell 批量文件名(不含扩展名)小写改大写
Cinnamon Applet 入门