<s> """<STR_LIT>""" <EOL> from collections import defaultdict <EOL> __author__ = '<STR_LIT>' <EOL> class Solution ( object ) : <EOL> def lengthOfLongestSubstringTwoDistinct ( self , s ) : <EOL> """<STR_LIT>""" <EOL> m = defaultdict ( int ) <EOL> i = <NUM_LIT:0> <EOL> j = <NUM_LIT:0> <EOL> maxa = <NUM_LIT:0> <EOL> for j in xrange ( len ( s ) ) : <EOL> m [ s [ j ] ] += <NUM_LIT:1> <EOL> while len ( m ) > <NUM_LIT:2> : <EOL> m [ s [ i ] ] -= <NUM_LIT:1> <EOL> if m [ s [ i ] ] == <NUM_LIT:0> : <EOL> del m [ s [ i ] ] <EOL> i += <NUM_LIT:1> <EOL> maxa = max ( maxa , j - i + <NUM_LIT:1> ) <EOL> return maxa <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> assert Solution ( ) . lengthOfLongestSubstringTwoDistinct ( "<STR_LIT>" ) == <NUM_LIT:7> </s>
