3. 无重复字符的最长子串(2019-01-12)

3. 无重复字符的最长子串(2019-01-12)_第1张图片
无重复字符的最长子串

class Solution {

    private Map map = new HashMap<>();

    public int lengthOfLongestSubstring(String s) {

        int i = 0;

        int max = 0;

        char temp = '\0';

        int start = -1;

        for (i = 0; i < s.length(); i ++) {

            temp = s.charAt(i);

            if (map.get(temp) != null) {

                start = Math.max(map.get(temp) , start);

            }

            max = Math.max(i - start, max);

            map.put(temp, i);

        }

        return max;

    }

}

你可能感兴趣的:(3. 无重复字符的最长子串(2019-01-12))