def lengthOfLongestSubstringTwoDistinct(self, s):
        """
        Sliding Window
        :type s: str
        :rtype: int
        """
        m = defaultdict(int)
        i = 0
        j = 0
        maxa = 0
        for j in xrange(len(s)):
            m[s[j]] += 1
            while len(m) > 2:
                m[s[i]] -= 1
                if m[s[i]] == 0:
                    del m[s[i]]

                i += 1

            maxa = max(maxa, j-i+1)

        return maxa
dataset/ETHPy150Open algorhythms/LeetCode/159 Longest Substring with At Most Two Distinct Characters.py/Solution.lengthOfLongestSubstringTwoDistinct/original