当前位置:网站首页>LeetCode_ 3 (longest substring without repeated characters)
LeetCode_ 3 (longest substring without repeated characters)
2022-07-05 14:13:00 【***】
Title Description :
Given a string s , Please find out that there are no duplicate characters in it Longest substrings The length of .
Example 1:
Input : s = “abcabcbb”
Output : 3
explain : Because the longest substring without repeating characters is “abc”, So its length is 3.
Example 2:
Input : s = “bbbbb”
Output : 1
explain : Because the longest substring without repeating characters is “b”, So its length is 1.
Example 3:
Input : s = “pwwkew”
Output : 3
explain : Because the longest substring without repeating characters is “wke”, So its length is 3. Please note that , you The answer must be Substring The length of ,“pwke” Is a subsequence , Not substring .
Tips :
0 <= s.length <= 5 * 104
s By the English letters 、 Numbers 、 Symbols and spaces
class Solution {
public int lengthOfLongestSubstring(String s) {
int ans=0;
if(s.equals(""))return 0;
if(s.length()==1)return 1;
int i=0,j=1,len=1;
while(j<s.length()){
// Traverse
for (int k = i; k < j; k++) {
// Traversal in the window
if(s.charAt(k)==s.charAt(j)){
// Determine whether there are repeated characters in the window
i=k+1;
len=j-i;
break;
}
}
len++;
if(len>ans)ans=len;
j++;
}
return ans;
}
}
边栏推荐
- Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
- Brief introduction to revolutionary neural networks
- Xampp configuring multiple items
- Shen Ziyu, nouveau Président de Meizu: M. Huang Zhang, fondateur de Meizu, agira comme conseiller stratégique pour les produits scientifiques et technologiques de Meizu
- 用“新”字来吸引好奇的人群
- openGauss数据库源码解析系列文章—— 密态等值查询技术详解(下)
- What is the future development trend of neural network Internet of things
- 国富氢能冲刺科创板:拟募资20亿 应收账款3.6亿超营收
- 为什么我认识的机械工程师都抱怨工资低?
- UE source code reading [1]--- starting with problems delayed rendering in UE
猜你喜欢
Recommendation number | what are interesting people looking at?
Postman简介、安装、入门使用方法详细攻略!
金融壹賬通香港上市:市值63億港元 葉望春稱守正篤實,久久為功
Redis如何实现多可用区?
Detailed explanation of IP address and preparation of DOS basic commands and batch processing
Interpretation of tiflash source code (IV) | design and implementation analysis of tiflash DDL module
神经网络物联网未来发展趋势怎么样
物联网应用技术专业是属于什么类
为什么我认识的机械工程师都抱怨工资低?
UE source code reading [1]--- starting with problems delayed rendering in UE
随机推荐
01 、Solr7.3.1 在Win10平台下使用jetty的部署及配置
Some ideas about Apache mesos
Recommendation number | what are interesting people looking at?
鏈錶(簡單)
根据CronSequenceGenerator计算cron表达式的时间
R language ggplot2 visual density map: Visual density map by group and custom configuration geom_ The alpha parameter in the density function sets the image transparency (to prevent multiple density c
R语言使用ggplot2包的geom_histogram函数可视化直方图(histogram plot)
Blue Bridge Cup study 2022.7.5 (morning)
Laravel dompdf exports PDF, and the problem of Chinese garbled code is solved
Don't be unconvinced. Mobile phone function upgrade is strong
[buuctf.reverse] 152-154
Mingfeng medical sprint technology innovation board: annual revenue of 350million yuan, proposed to raise 624million yuan
Leetcode array question brushing notes
Discussion on memset assignment
魅族新任董事长沈子瑜:创始人黄章先生将作为魅族科技产品战略顾问
In addition to the root directory, other routes of laravel + xampp are 404 solutions
R language ggplot2 visual bar graph: visualize the bar graph through the two-color gradient color theme, and add label text for each bar (geom_text function)
2022 machine fitter (Advanced) test question simulation test question bank simulation test platform operation
Liste des liens (simple)
IP packet header analysis and static routing