import java.util.HashSet;/*** @Author :田宇寒.* @Date :Created in 14:19 2021年5月28日* @Description:leetcode3题 最大子串长度* @Modified By:* @Version: 1.0$*/public class code3 {class Solution {public int lengthOfLongestSubstring(String s) {/*** create by: 田宇寒* description: 滑动窗口 时间复杂度O(N) 空间复杂度O(|E|) E表示字符集 |E|表示字符集大小* create time: 14:32 2021年5月28日* @Param: s* @return int*/HashSet<Character> characterHashSet = new HashSet<>(s.length());int end = -1;int maxLength = 0;for (int i = 0; i < s.length(); i++) {if (i > 0) {characterHashSet.remove(s.charAt(i - 1));}while (end + 1 < s.length() && !characterHashSet.contains(s.charAt(end + 1))) {characterHashSet.add(s.charAt(end + 1));++end;}maxLength = maxLength > end - i + 1? maxLength : end - i + 1;}return maxLength;}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。