当前位置:网站首页>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;
}
边栏推荐
- Index in MySQL show index from XXX the meaning of each parameter
- Naming specification / annotation specification / logical specification
- PDSCH related
- SSL引入原因及加密步骤
- ARP protocol data processing process of neighbor subsystem
- 机器学习之线性模型
- Load/store access instruction of arm instruction set (2)
- [foundation of deep learning] back propagation method (1)
- ARM指令集之杂类指令
- [foundation of deep learning] learning of neural network (4)
猜你喜欢

Lambda and filter, List 和 numpy array的索引,以及各种距离指标distance-metrics,拼接数组以及axis=0 and axis=1的区分

Inter class and intra class relations in video classification -- regularization

Doris records service interface calls

6.6 separate convolution

LeetCode 497. Random points in non overlapping rectangles (prefix and + bisection)

Unlimited growth, we will all go to the future | the 15th anniversary of the founding of InfoQ China

C# 37. Textbox scroll bar and multiline

Cookies and sessions

Reprint --win10 open the task manager to solve the blue screen problem
![[foundation of deep learning] back propagation method (1)](/img/0b/540c1f94712a381cae4d30ed624778.png)
[foundation of deep learning] back propagation method (1)
随机推荐
K52. Chapter 1: installing kubernetes v1.22 based on kubeadm -- cluster deployment
[QNX hypervisor 2.2 user manual] 4.1 method of building QNX hypervisor system
Kubernetes cluster setup
Miscellaneous instructions of arm instruction set
Design of secure chat tool based on C #
LeetCode 1037. 有效的回旋镖(向量叉乘)
[database] SQLite version upgrade and downgrade
Multiplication instruction of arm instruction set
ioremap
視頻分類的類間和類內關系——正則化
Why is there no traffic after the launch of new products? How should new products be released?
如何确定首页和搜索之间的关系呢?首页与搜索的关系
QML first day
创建Servlet项目
K53. Chapter 2 installing kubernetes v1.22 based on binary packages -- cluster deployment
The second regular match is inconsistent with the first one, and the match in the regular loop is invalid
IP address management
ARM指令集之Load/Store指令寻址方式(二)
ARM指令集之Load/Store指令寻址方式(一)
MySQL - built in function
