标签:lse tar har str contain ret boolean character i+1
法一:暴力法
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; } }
标签:lse tar har str contain ret boolean character i+1
原文地址:https://www.cnblogs.com/running-world/p/10592173.html