public static int lengthOfLongestSubstring(String s) { int len = s.length(); int res = 0; int start = 0; int end = 0; HashSet set = new HashSet(); while (start < s.length() && end < s.length()) { if (set.contains(s.charAt(end))) { set.remove(s.charAt(start)); start++; } else { set.add(s.charAt(end)); end++; res = Math.max(res, end - start); } } return res; }
原文地址:https://www.cnblogs.com/pusan/p/12219841.html
时间: 2024-09-30 20:35:41