标签:char color star for cte longest ash set pre
public 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; } }
给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
标签:char color star for cte longest ash set pre
原文地址:https://www.cnblogs.com/Yanss/p/12068017.html