import java.util.HashMap; public static int lengthOfLongestSubstring(String s) { if (s == null || s.length() == 0) return 0; int len = s.length(); int max = 0, leftBound = 0; HashMap<Character, Integer> map = new HashMap<>(); for (int i = 0; i < len; i++) { char c = s.charAt(i); int tempBound = map.containsKey(c) ? map.get(c) + 1 : 0; leftBound = Math.max(leftBound, tempBound);// 滑动窗口的左门限 max = Math.max(max, i - leftBound + 1); map.put(c, i); } return max; }
点赞 1

相关推荐

讲原则的小黄鸭不愿吃...:有时候面试眼缘确实很重要,当然,飞驰人生2中张弛说的很对:我努力了无数次,但是我知道机会只会出现在其中一两次。你把每一次笔试面试都全力以赴,总有你运气发挥到位的时候
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务