当前位置:网站首页>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;
}
}
边栏推荐
- Tiflash compiler oriented automatic vectorization acceleration
- Mingfeng medical sprint technology innovation board: annual revenue of 350million yuan, proposed to raise 624million yuan
- 最长公共子序列 - 动态规划
- 分享 20 个稀奇古怪的 JS 表达式,看看你能答对多少
- MySQL user-defined function ID number to age (supports 15 / 18 digit ID card)
- 神经网络物联网未来现状和趋势及看法
- Make the seckill Carnival more leisurely: the database behind the promotion (Part 2)
- 为什么我认识的机械工程师都抱怨工资低?
- Show strength. In this way, the mobile phone will not be difficult to move forward
- SAS接口有什么优势特点
猜你喜欢

区间 - 左闭右开

Redis如何实现多可用区?

Zhizhen new energy rushes to the scientific innovation board: the annual revenue is 220million, and SAIC venture capital is the shareholder
![UE source code reading [1]--- starting with problems delayed rendering in UE](/img/fa/f33242b01e4da973fa36c2c6f23db6.png)
UE source code reading [1]--- starting with problems delayed rendering in UE

Sorter evolution of ticdc 6.0 principle

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

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

Introduction, installation, introduction and detailed introduction to postman!

Postman简介、安装、入门使用方法详细攻略!

Lepton 无损压缩原理及性能分析
随机推荐
无密码身份验证如何保障用户隐私安全?
Hongmeng fourth training
R语言使用ggplot2包的geom_histogram函数可视化直方图(histogram plot)
01. Solr7.3.1 deployment and configuration of jetty under win10 platform
C - Divisors of the Divisors of An Integer Gym - 102040C
LeetCode_69(x 的平方根 )
Lepton 无损压缩原理及性能分析
基于伯努利原理的速度监测芯片可用于天然气管道泄露检测
让秒杀狂欢更从容:大促背后的数据库(下篇)
How to call the function mode of one hand and one machine
瑞能实业IPO被终止:年营收4.47亿 曾拟募资3.76亿
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
鸿蒙第四次培训
JS takes key and value from an array object to form a new object
R language ggplot2 visualization: visual line graph, using legend in theme function The position parameter defines the position of the legend
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
Linked list (simple)
mysql 自定义函数 身份证号转年龄(支持15/18位身份证)
故障分析 | MySQL 耗尽主机内存一例分析
R Language ggplot2 Visualization: visualize linegraph, using Legend in Theme function. Paramètre de position emplacement de la légende personnalisée