当前位置:网站首页>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")
边栏推荐
- 10 张图打开 CPU 缓存一致性的大门
- Flink | multi stream conversion
- 信号强度(RSSI)知识整理
- MySQL error 28 and solution
- ESP32构解工程添加组件
- JS determines whether an object is empty
- 作战图鉴:12大场景详述容器安全建设要求
- clion mingw64中文乱码
- Pay close attention to the work of safety production and make every effort to ensure the safety of people's lives and property
- DETR介绍
猜你喜欢
LIS longest ascending subsequence problem (dynamic programming, greed + dichotomy)
Introduce six open source protocols in detail (instructions for programmers)
10 张图打开 CPU 缓存一致性的大门
Esp32 construction engineering add components
将数学公式在el-table里面展示出来
1、深拷贝 2、call apply bind 3、for of for in 区别
OSI 七层模型
MongoDB内部的存储原理
实现IP地址归属地显示功能、号码归属地查询
我那“不好惹”的00后下属:不差钱,怼领导,抵制加班
随机推荐
工具箱之 IKVM.NET 项目新进展
toRaw和markRaw
Milkdown 控件图标
flask session伪造之hctf admin
MongoDB复制(副本集)总结
【堡垒机】云堡垒机和普通堡垒机的区别是什么?
记一次 .NET 某新能源系统 线程疯涨 分析
QQ medicine, Tencent ticket
DID登陆-MetaMask
分屏bug 小记
Talk about pseudo sharing
Getting started with MySQL
What parameters need to be reconfigured to replace the new radar of ROS robot
Esp32 series column
Storage principle inside mongodb
Pcap learning notes II: pcap4j source code Notes
Esp32 ① compilation environment
高端了8年,雅迪如今怎么样?
OSI 七层模型
Show the mathematical formula in El table