当前位置:网站首页>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")
边栏推荐
- Summary of import, export, backup and recovery of mongodb
- LeetCode_二分搜索_中等_153.寻找旋转排序数组中的最小值
- Deep understanding of array related problems in C language
- How to make the new window opened by electorn on the window taskbar
- Some principles of mongodb optimization
- 单片机原理期末复习笔记
- QQ的药,腾讯的票
- Move base parameter analysis and experience summary
- flask session伪造之hctf admin
- Final review notes of single chip microcomputer principle
猜你喜欢
随机推荐
[learning notes] agc010
MongoDB 遇见 spark(进行整合)
[Presto profile series] timeline use
MongoDB的用户管理总结
Cinnamon Applet 入门
Move base parameter analysis and experience summary
QQ medicine, Tencent ticket
Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)
信号强度(RSSI)知识整理
工具箱之 IKVM.NET 项目新进展
LeetCode_ Binary search_ Medium_ 153. Find the minimum value in the rotation sort array
Show the mathematical formula in El table
[1] ROS2基础知识-操作命令总结版
Enregistrement de la navigation et de la mise en service du robot ROS intérieur (expérience de sélection du rayon de dilatation)
Simple and easy-to-use code specification
xshell连接服务器把密钥登陆改为密码登陆
toRaw和markRaw
2022-7-7 Leetcode 34.在排序数组中查找元素的第一个和最后一个位置
OSI 七层模型
High end for 8 years, how is Yadi now?