当前位置:网站首页>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;
}
}
边栏推荐
- In addition to the root directory, other routes of laravel + xampp are 404 solutions
- Why do I support bat to dismantle "AI research institute"
- 让秒杀狂欢更从容:大促背后的数据库(下篇)
- 无密码身份验证如何保障用户隐私安全?
- 04_ Use of solrj7.3 of solr7.3
- The forked VM terminated without saying properly goodbye
- Why do mechanical engineers I know complain about low wages?
- 循环不变式
- Sqllab 1-6 exercise
- 享你所想。智创未来
猜你喜欢
-Web direction attack and defense world
TiFlash 面向编译器的自动向量化加速
TiFlash 源码解读(四) | TiFlash DDL 模块设计及实现分析
让秒杀狂欢更从容:大促背后的数据库(下篇)
Anchor navigation demo
基于 TiDB 场景式技术架构过程 - 理论篇
软件测试人在深圳有哪些值得去的互联网公司【软件测试人员专供版】
魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問
循环不变式
Scenario based technology architecture process based on tidb - Theory
随机推荐
Laravel dompdf exports PDF, and the problem of Chinese garbled code is solved
判断变量是否为数组
Discussion on memset assignment
C - Divisors of the Divisors of An Integer Gym - 102040C
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)
SSH免密码登录详解
魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問
鸿蒙第四次培训
故障分析 | MySQL 耗尽主机内存一例分析
Login interface code
The speed monitoring chip based on Bernoulli principle can be used for natural gas pipeline leakage detection
[buuctf.reverse] 152-154
2022 construction welder (special type of construction work) special operation certificate examination question bank and online simulation examination
分享 12 个最常用的正则表达式,能解决你大部分问题
R语言ggplot2可视化:使用ggplot2可视化散点图、使用labs参数自定义X轴的轴标签文本(customize X axis labels)
R language ggplot2 visualization: visual line graph, using legend in theme function The position parameter defines the position of the legend
如何将 DevSecOps 引入企业?
openGauss数据库源码解析系列文章—— 密态等值查询技术详解(下)
Laravel - view (new and output views)
Use the word "new" to attract curious people