当前位置:网站首页>Chaîne la plus longue sans caractères dupliqués (leetcode 3)
Chaîne la plus longue sans caractères dupliqués (leetcode 3)
2022-06-12 11:56:00 【Li Yihe bat Xiao Pi】
Page d'accueil de l'auteur:Li Yihe bat le blog de Xiao Pi
* Introduction personnelle:Bonjour tout le monde,Je m'appelle Li Yihe.!( ̄▽ ̄)~*
N'oublie pas d'être sympa、Collection、Commentaires️️️
Étudier sérieusement!!!
Catalogue des articles
Donner une chaîne s ,Veuillez trouver ceux qui ne contiennent pas de caractères dupliqués Substrat le plus long Longueur.
Solution 1:Fenêtre coulissante
Parce que pour trouver la chaîne la plus longue qui ne se répète pas,Il nous faut deux pointeurs,Le pointeur gauche est fixé en premier,Les pointeurs de droite sont ajoutés à la collection un par un,Déterminer à chaque fois s'il y a des valeurs en double,Si c'est le cas, c'est fini,Déterminer la longueur de cette fois par rapport à la dernière,Puis le pointeur gauche se déplace vers la droite,Puis le pointeur droit poursuit l'opération ci - dessus jusqu'à la fin.
public int lengthOfLongestSubstring(String s) {
Set<Character> set=new HashSet<Character>();
int length=s.length();
int rigth=0,max=0;
for(int i=0;i<length;i++){
if(i!=0)
set.remove(s.charAt(i-1));
while(rigth<length&&!set.contains(s.charAt(rigth))){
set.add(s.charAt(rigth));
rigth++;
}
max=Math.max(max,rigth-i);
}
return max;
}
边栏推荐
- 机器学习之决策树
- MySQL lock leak detection and defect filling
- 机器学习之线性模型
- Cookie和Session
- 淘宝新改版商家如何操作,需要注意的点有哪些
- Spark common encapsulation classes
- One must keep writing, so as not to be submerged by the vast crowd.
- Relatively rare exception records in UI automation test
- Lambda and filter, index of list and numpy array, as well as various distance metrics, concatenated array and distinction between axis=0 and axis=1
- 一个人必须不停地写作,才能不被茫茫人海淹没。
猜你喜欢

QT adds a summary of the problems encountered in the QObject class (you want to use signals and slots) and solves them in person. Error: undefined reference to `vtable for xxxxx (your class name)‘

Reprint --win10 open the task manager to solve the blue screen problem

5G NR協議學習--TS38.211下行通道

ARM处理器模式与寄存器

Create servlet project

视频分类的类间和类内关系——正则化

M-arch (fanwai 10) gd32l233 evaluation -spi drive DS1302

Design of secure chat tool based on C #

C# 35. Select default network card

C# 37. Textbox scroll bar and multiline
随机推荐
視頻分類的類間和類內關系——正則化
Spark常用封装类
Socket implements TCP communication flow
Blue Bridge Cup 2015 CA provincial competition (filling the pit)
Getting started with NVIDIA Jetson nano Developer Kit
Rich text editor copying pictures in word documents
JS to load and display Excel files
Must do skill -- use ffmpeg command to quickly and accurately cut video
ARM指令集之杂类指令
PDSCH 相关
UML系列文章(30)体系结构建模---制品图
Relation entre les classes et à l'intérieur des classes de classification vidéo - - Régularisation
Google Earth Engine(GEE)——Kmeans聚类快速进行土地分类(双for循环快速调参)
Neighbor item status update of neighbor subsystem
Load/store instruction addressing mode of arm instruction set (2)
Go sends SMS based on alicloud
Spark common encapsulation classes
K53. Chapter 2 installing kubernetes v1.22 based on binary packages -- cluster deployment
UML系列文章(31)体系结构建模---部署图
Logrotate log rotation method create and copyruncate principles
