当前位置:网站首页>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;
}
}
边栏推荐
- 3W原则[通俗易懂]
- Sorter evolution of ticdc 6.0 principle
- Login interface code
- Detailed explanation of IP address and preparation of DOS basic commands and batch processing
- SAS接口有什么优势特点
- 清大科越冲刺科创板:年营收2亿 拟募资7.5亿
- Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]
- How to call the function mode of one hand and one machine
- 享你所想。智创未来
- Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
猜你喜欢

治臻新能源冲刺科创板:年营收2.2亿 上汽创投是股东

循环不变式

如何将 DevSecOps 引入企业?

Zhizhen new energy rushes to the scientific innovation board: the annual revenue is 220million, and SAIC venture capital is the shareholder

Lepton 无损压缩原理及性能分析

What is the future development trend of neural network Internet of things

LeetCode_2(两数相加)

Simple process of penetration test

Deep copy is hard

Brief introduction to revolutionary neural networks
随机推荐
PHP5下WSDL,SOAP调用实现过程
总量分析 核算方法和势方法 - 分摊分析
Some ideas about Apache mesos
登录界面代码
治臻新能源冲刺科创板:年营收2.2亿 上汽创投是股东
3W原则[通俗易懂]
Shenziyu, the new chairman of Meizu: Mr. Huang Zhang, the founder, will serve as the strategic adviser of Meizu's scientific and technological products
In addition to the root directory, other routes of laravel + xampp are 404 solutions
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
Interpretation of tiflash source code (IV) | design and implementation analysis of tiflash DDL module
Don't be unconvinced. Mobile phone function upgrade is strong
LeetCode_67(二进制求和)
Google EventBus 使用详解
openGauss数据库源码解析系列文章—— 密态等值查询技术详解(下)
为什么我认识的机械工程师都抱怨工资低?
Anchor navigation demo
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)
Laravel dompdf exports PDF, and the problem of Chinese garbled code is solved
用“新”字来吸引好奇的人群
别不服气。手机功能升级就是强