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

2019-01-12  本文已影响0人  Rondo9
无重复字符的最长子串

class Solution {

    private Map<Character, Integer> 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;

    }

}

上一篇下一篇

猜你喜欢

热点阅读