Created
July 7, 2017 21:20
-
-
Save sreevidyavutukuru/dce900f30c6c2cfa7bef27fbbc368f71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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