public int lengthOfLongestSubstring(String s) {
        int length = s.length();
        int max = 0;
        int index = -1;// 为了保证length =1 时正确。
        Map<Character,Integer> map = new HashMap<Character,Integer>();
        for (int i =0; i < length;i++){
            char key = s.charAt(i);
            if(map.containsKey(key) && index < map.get(key))
                index = map.get(key);
            max = Math.max(max,i - index);
            map.put(key,i);
        }
        return max;
    }