当前位置:网站首页>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;
}
}
边栏推荐
- upload (1-6)
- 基于 TiDB 场景式技术架构过程 - 理论篇
- 登录界面代码
- Shenziyu, the new chairman of Meizu: Mr. Huang Zhang, the founder, will serve as the strategic adviser of Meizu's scientific and technological products
- 最长公共子序列 - 动态规划
- 展现强大。这样手机就不会难前进
- The IPO of Ruineng industry was terminated: the annual revenue was 447million and it was planned to raise 376million
- 循环不变式
- 3W principle [easy to understand]
- How to call the function mode of one hand and one machine
猜你喜欢

分享 12 个最常用的正则表达式,能解决你大部分问题

昆仑太科冲刺科创板:年营收1.3亿拟募资5亿 电科太极持股40%

TiCDC 6.0原理之Sorter演进

魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問

魅族新任董事长沈子瑜:创始人黄章先生将作为魅族科技产品战略顾问

Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting

What are the advantages and characteristics of SAS interface

Kunlun Taike rushes to the scientific innovation board: the annual revenue is 130million, and it plans to raise 500million. CETC Taiji holds 40% of the shares

无密码身份验证如何保障用户隐私安全?

清大科越冲刺科创板:年营收2亿 拟募资7.5亿
随机推荐
Matlab learning 2022.7.4
Make the seckill Carnival more leisurely: the database behind the promotion (Part 2)
Some ideas about Apache mesos
一网打尽异步神器CompletableFuture
R language dplyr package select function, group_ By function, mutate function and cumsum function calculate the cumulative value of the specified numerical variable in the dataframe grouping data and
根据CronSequenceGenerator计算cron表达式的时间
金融壹账通香港上市:市值63亿港元 叶望春称守正笃实,久久为功
2022 machine fitter (Advanced) test question simulation test question bank simulation test platform operation
让秒杀狂欢更从容:大促背后的数据库(下篇)
Sorter evolution of ticdc 6.0 principle
04_solr7.3之solrJ7.3的使用
动态规划
upload (1-6)
物联网应用技术专业是属于什么类
The IPO of Ruineng industry was terminated: the annual revenue was 447million and it was planned to raise 376million
魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問
JS takes key and value from an array object to form a new object
How to introduce devsecops into enterprises?
怎么叫一手一机的功能方式
最长公共子序列 - 动态规划