当前位置:网站首页>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;
}
}
边栏推荐
- Linked list (simple)
- R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用coef函数获取模型中每个变量(自变量改变一个单位)对应的对数优势比(log odds ratio)
- 不相交集
- 04_ Use of solrj7.3 of solr7.3
- Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]
- Mingfeng medical sprint technology innovation board: annual revenue of 350million yuan, proposed to raise 624million yuan
- Tiflash compiler oriented automatic vectorization acceleration
- SSH免密码登录详解
- 让秒杀狂欢更从容:大促背后的数据库(下篇)
- Laravel - model (new model and use model)
猜你喜欢
Xampp configuring multiple items
Comparison of several distributed databases
神经网络物联网未来发展趋势怎么样
Detailed explanation of IP address and preparation of DOS basic commands and batch processing
基于 TiDB 场景式技术架构过程 - 理论篇
明峰医疗冲刺科创板:年营收3.5亿元 拟募资6.24亿
为什么我认识的机械工程师都抱怨工资低?
Shenziyu, the new chairman of Meizu: Mr. Huang Zhang, the founder, will serve as the strategic adviser of Meizu's scientific and technological products
IP packet header analysis and static routing
What are the advantages and characteristics of SAS interface
随机推荐
治臻新能源冲刺科创板:年营收2.2亿 上汽创投是股东
How to deeply understand the design idea of "finite state machine"?
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
Google EventBus 使用详解
常见问题之PHP——Fatal error: Allowed memory size of 314572800 bytes exhausted...
Some ideas about Apache mesos
国富氢能冲刺科创板:拟募资20亿 应收账款3.6亿超营收
别不服气。手机功能升级就是强
做自媒体视频二次剪辑,怎样剪辑不算侵权
魅族新任董事长沈子瑜:创始人黄章先生将作为魅族科技产品战略顾问
关于Apache Mesos的一些想法
Don't be unconvinced. Mobile phone function upgrade is strong
tidb-dm报警DM_sync_process_exists_with_error排查
R语言ggplot2可视化:gganimate包基于transition_time函数创建动态散点图动画(gif)、使用shadow_mark函数为动画添加静态散点图作为动画背景
如何深入理解“有限状态机”的设计思想?
What are the advantages and characteristics of SAS interface
Lepton 无损压缩原理及性能分析
Scenario based technology architecture process based on tidb - Theory
Make the seckill Carnival more leisurely: the database behind the promotion (Part 2)
Why do I support bat to dismantle "AI research institute"