剑指 Offer 48:
请从字符串中找出一个最长的不包含重复字符的子字符串,计算该最长子字符串的长度。
class Solution {public int lengthOfLongestSubstring(String s) {if (s == null || s.length() == 0) {return 0;}int max = Integer.MIN_VALUE;HashMap<Character, Integer> hashMap = new HashMap<>();char[] charArray = s.toCharArray();for (int i = 0; i < charArray.length; i++) {if (hashMap.containsKey(charArray[i])) {i = hashMap.get(charArray[i]);max = hashMap.size() > max ? hashMap.size() : max;hashMap = new HashMap<>();} else {hashMap.put(charArray[i], i);}}max = hashMap.size() > max ? hashMap.size() : max;return max;}}
