Skip to content

Instantly share code, notes, and snippets.

@sreevidyavutukuru
Created July 7, 2017 21:20
Show Gist options
  • Save sreevidyavutukuru/dce900f30c6c2cfa7bef27fbbc368f71 to your computer and use it in GitHub Desktop.
Save sreevidyavutukuru/dce900f30c6c2cfa7bef27fbbc368f71 to your computer and use it in GitHub Desktop.
class Solution(object):
def lengthOfLongestSubstringTwoDistinct(self, s):
"""
:type s: str
:rtype: int
"""
sublen = 1
substrings = []
result = {}
for i in range(0,len(s)+1):
result[i] = []
for i in range(1,len(s)+1):
for j in range(0,len(s)-i+1):
#print s[j:j+i]
SubString = s[j:j+i]
SubString_dict= ''.join(set(s[j:j+i]))
#print len(s[j:j+i])
#print len(SubString_dict)
result[len(SubString_dict)].append(len(s[j:j+i]))
#print result
max = 0
for val in result:
if val <=2:
for ival in result[val]:
if ival > max:
max = ival
return max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment