leetcode 3. Longest Substring Without Repeating Characters [java]
Posted why
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode 3. Longest Substring Without Repeating Characters [java]相关的知识,希望对你有一定的参考价值。
public int lengthOfLongestSubstring(String s) {
int i = 0, j = 0, max = 0;
Set<Character> set = new HashSet<>();
while(j < s.length()){
if(! set.contains(s.charAt(j)) ){
set.add(s.charAt(j++));
max = Math.max(max, set.size());
}else{
set.remove(s.charAt(i++));
}
}
return max;
}
以上是关于leetcode 3. Longest Substring Without Repeating Characters [java]的主要内容,如果未能解决你的问题,请参考以下文章
Leetcode 3. Longest Substring Without Repeating Characters
LeetCode 3. Longest Substring Without Repeating
3. 没有重复字母的最长子串 [leetcode 3: Longest Substring Without Repeating Characters]
3. 没有重复字母的最长子串 [leetcode 3: Longest Substring Without Repeating Characters]
leetcode longest consecutive sequence
leetcode 3. Longest Substring Without Repeating Characters (Python版)