当前位置:网站首页>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;
}
}
边栏推荐
- 明峰医疗冲刺科创板:年营收3.5亿元 拟募资6.24亿
- Show strength. In this way, the mobile phone will not be difficult to move forward
- Scenario based technology architecture process based on tidb - Theory
- How to deeply understand the design idea of "finite state machine"?
- openGauss数据库源码解析系列文章—— 密态等值查询技术详解(下)
- 不相交集
- R language ggplot2 visualization: gganimate package is based on Transition_ The time function creates dynamic scatter animation (GIF) and uses shadow_ Mark function adds static scatter diagram as anim
- 总量分析 核算方法和势方法 - 分摊分析
- Detailed explanation of IP address and preparation of DOS basic commands and batch processing
- Zhizhen new energy rushes to the scientific innovation board: the annual revenue is 220million, and SAIC venture capital is the shareholder
猜你喜欢

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

Deep copy is hard

Laravel dompdf exports PDF, and the problem of Chinese garbled code is solved

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

金融壹賬通香港上市:市值63億港元 葉望春稱守正篤實,久久為功

非技术部门,如何参与 DevOps?

软件测试人在深圳有哪些值得去的互联网公司【软件测试人员专供版】

为什么我认识的机械工程师都抱怨工资低?

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

神经网络物联网未来现状和趋势及看法
随机推荐
Mingfeng medical sprint technology innovation board: annual revenue of 350million yuan, proposed to raise 624million yuan
TiCDC 6.0原理之Sorter演进
Oneconnect listed in Hong Kong: with a market value of HK $6.3 billion, ye Wangchun said that he was honest and trustworthy, and long-term success
WebRTC的学习(二)
鸿蒙第四次培训
TiFlash 面向编译器的自动向量化加速
R language ggplot2 visualization: visual line graph, using legend in theme function The position parameter defines the position of the legend
Show strength. In this way, the mobile phone will not be difficult to move forward
Scenario based technology architecture process based on tidb - Theory
upload (1-6)
最简单不用证书也可以多开功能的方式
Geom of R language using ggplot2 package_ Histogram function visual histogram (histogram plot)
JS takes key and value from an array object to form a new object
Guofu hydrogen energy rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, and 360million yuan of accounts receivable exceed the revenue
Linked list (simple)
UE source code reading [1]--- starting with problems delayed rendering in UE
LeetCode_69(x 的平方根 )
Shenziyu, the new chairman of Meizu: Mr. Huang Zhang, the founder, will serve as the strategic adviser of Meizu's scientific and technological products
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the coef function to obtain the log odds ratio corresponding to eac
物联网应用技术专业是属于什么类