当前位置:网站首页>Topic24——3. 无重复字符的最长子串
Topic24——3. 无重复字符的最长子串
2022-06-09 05:38:00 【_卷心菜_】
题目:给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。
示例 1:
输入: s = "abcabcbb"
输出: 3
解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。
示例 2:
输入: s = "bbbbb"
输出: 1
解释: 因为无重复字符的最长子串是 "b",所以其长度为 1。
示例 3:
输入: s = "pwwkew"
输出: 3
解释: 因为无重复字符的最长子串是 "wke",所以其长度为 3。
请注意,你的答案必须是 子串 的长度,"pwke" 是一个子序列,不是子串。
提示:
0 <= s.length <= 5 * 104
s 由英文字母、数字、符号和空格组成
class Solution {
public int lengthOfLongestSubstring(String s) {
if(s.length() == 0)
return 0;
int[] memo = new int[s.length()];
Arrays.fill(memo, 1);
int i = 1;
int max = 1;
while(i < s.length()) {
for(int j = i - 1; j > i - memo[i - 1] - 1; j--) {
if(s.charAt(j) != s.charAt(i)) {
memo[i] = memo[i] + 1;
} else {
break;
}
}
max = Math.max(max, memo[i]);
i++;
}
return max;
}
}
边栏推荐
- Mysql5 available clusters
- Alibaba cloud AI training camp - SQL basics 3: complex query methods - views, subqueries, functions, etc
- [it] Foxit PDF retention tool selection
- Seaweedfs client adapts to the higher version of seaweedfs service
- Yolov5-6.0 series | yolov5 model network construction
- [it] Fuxin PDF Keeping Tool Selection
- MRNA factory| quantitative detection of LNP encapsulated RNA content by ribogreen
- Ffmpeg pulls webrtc streams, and the first all open source solution in the metartc industry is coming
- Youshimu V8 projector opens the "vision" field of high fresh
- Alibaba cloud AI training camp -sql foundation 2: query and sorting
猜你喜欢

Yolov5-6.0系列 | yolov5的模块设计

synchronized 详细解析

Heap and priority queues

Fundamentals of deep learning: face based common expression recognition (2) - data acquisition and collation

Good hazelnut comes from Liaoyang!

Several implementation methods of redis distributed lock

2022年11月15日起,代码签名证书私钥均需存储在硬件加密模块中

Alibaba cloud AI training camp - machine learning 3:lightgbm

Yolov5-6.0 series | yolov5 module design

Once, the online environment redis response was slow, causing an avalanche
随机推荐
seaweedfs-client适配高版本的seaweedfs服务
Yolov5-6.0 series | yolov5 module design
Alibaba cloud AI training camp -sql foundation 2: query and sorting
关于AIR代码签名及发布者标识符的相关介绍
Data inconsistency between the reids cache and the database, cache expiration and deletion
CEF 拦截URL,重定向新的网址
Detailed explanation of groupby function
“Ran out of input” while use WikiExtractor
使用MAT进行内存问题定位
冒泡排序,打印菱形,打印直角三角形,打印倒三角,打印等边三角形,打印九九乘法表
An article takes you to know what token is
AQS 之 Semaphore 源码分析
Apache Devlake 代码库导览
@Differences between jsonformat and @datetimeformat
SSL证书安装后网站还是显示不安全
[it] Foxit PDF retention tool selection
数据血缘用例与扩展实践
FPGA based TDC Research Report
validate-npm-package-name
Practical guide to GStreamer application development (III)