当前位置:网站首页>Topic24——3. Longest substring without duplicate characters
Topic24——3. Longest substring without duplicate characters
2022-06-09 05:44:00 【_ Cabbage_】
subject : 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 , Your 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) {
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;
}
}
边栏推荐
- Record an opensips DNS problem
- Leetcode 929. Unique email address
- Yolov5-6.0系列 | yolov5的模块设计
- Quelles sont les informations contenues dans le certificat SSL?
- 计网中的一些概念
- AspNetPager combines stored procedure paging to speed up access
- function
- duilib内核原理分析 之 窗口 关闭流程
- Source code analysis of cyclicbarrier in AQS
- Interview process and thread
猜你喜欢

Ecmascript6.0 Basics

TCP error control, flow control, congestion control

Practical guide to GStreamer application development (III)

Bubble sort, print diamond, print right triangle, print inverted triangle, print equilateral triangle, print 99 multiplication table

Morsel driven parallelism: a NUMA aware parallel query execution framework
Detailed explanation of groupby function

Interview process and thread

Two methods of unbutu installing ffmpeg

Basic knowledge of deep learning: face based common expression recognition (1)

redis 分布式锁的几种实现方式
随机推荐
Data inconsistency between the reids cache and the database, cache expiration and deletion
IP address division and subnet
Source code analysis of cyclicbarrier in AQS
Swift protocol
Vector of STL
线程thread 中join方法解读
Xtrabackup backup and recovery
Debian11 fix the port number after installing NFS server to set firewall
【IT】福昕pdf保持工具选择
Article title
Once, the online environment redis response was slow, causing an avalanche
数据血缘用例与扩展实践
Practical guide to GStreamer application development (I)
Heqibao's trip to Chongqing ~
XML modeling
Alibaba cloud AI training camp -sql foundation 2: query and sorting
2022年11月15日起,代码签名证书私钥均需存储在硬件加密模块中
Fundamentals of deep learning: face based common expression recognition (2) - data acquisition and collation
【IT】福昕pdf保持工具選擇
Concept and compilation of DTD