Blankj/awesome-java-leetcode

003

MohnSnow opened this issue · 0 comments

private static int lengthOfLongestSubstringMe(String s) {
HashMap<Character, Integer> map = new HashMap<>(128);
int max = 0;
int pre = 0;
char temp;
for (int i = 0; i < s.length(); i++) {
temp = s.charAt(i);
if (map.containsKey(temp)) {
max = Math.max(max, i - pre);
pre = Math.max(map.get(temp) + 1, pre);
}
map.put(s.charAt(i), i);
}
return Math.max(max, s.length() - pre);
}