当前位置:网站首页>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")
边栏推荐
- 室內ROS機器人導航調試記錄(膨脹半徑的選取經驗)
- 2022-7-6 初学redis(一)在 Linux 下下载安装并运行 redis
- 聊聊伪共享
- QQ的药,腾讯的票
- [QNX hypervisor 2.2 user manual]6.3.4 virtual register (guest_shm.h)
- Unity build error: the name "editorutility" does not exist in the current context
- Show the mathematical formula in El table
- DETR介绍
- Scrapy教程经典实战【新概念英语】
- LeetCode_ Binary search_ Medium_ 153. Find the minimum value in the rotation sort array
猜你喜欢

MySQL入门尝鲜

记一次 .NET 某新能源系统 线程疯涨 分析

How to make join run faster?

如何让join跑得更快?

10 pictures open the door of CPU cache consistency
![[Presto profile series] timeline use](/img/c6/83c4fdc5f001dab34ecf18c022d710.png)
[Presto profile series] timeline use

DID登陆-MetaMask

Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)

实现IP地址归属地显示功能、号码归属地查询

My "troublesome" subordinates after 00: not bad for money, against leaders, and resist overtime
随机推荐
一文读懂数仓中的pg_stat
Mongodb slice summary
Read PG in data warehouse in one article_ stat
Split screen bug notes
Error lnk2019: unresolved external symbol
JNA learning notes 1: Concepts
提升树莓派性能的方法
信号强度(RSSI)知识整理
Ways to improve the performance of raspberry pie
单片机学习笔记之点亮led 灯
QQ medicine, Tencent ticket
clion mingw64中文乱码
迅为iTOP-IMX6ULL开发板Pinctrl和GPIO子系统实验-修改设备树文件
Ogre入门尝鲜
Digital IC Design SPI
MySQL入门尝鲜
Problems that cannot be accessed in MySQL LAN
最佳实践 | 用腾讯云AI意愿核身为电话合规保驾护航
服务器到服务器 (S2S) 事件 (Adjust)
Final review notes of single chip microcomputer principle