无重复字符的最长子串

Posted running-world

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无重复字符的最长子串相关的知识,希望对你有一定的参考价值。

法一:暴力法
class
Solution { public int lengthOfLongestSubstring(String s) { int n=s.length(); int ans=0; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if(allUnique(s,i,j)) ans=Math.max(ans,j-i); } } return ans; } public boolean allUnique(String s,int start,int end){ Set<Character> set = new HashSet<>(); for(int i=start;i<end;i++){ Character ch = s.charAt(i); if(set.contains(ch)) return false; set.add(ch); } return true; } }

 

以上是关于无重复字符的最长子串的主要内容,如果未能解决你的问题,请参考以下文章

3. 无重复字符的最长子串

符串的最长无重复字符的子串长度

算法--最长无重复字符子串

Leetcode 3.无重复字符的最长子串(带图)

无重复字符的最长子串

无重复字符的最长子串