Created
July 14, 2019 12:03
-
-
Save alaisgomes/598ca5612df3d37ebbb372582b7d0561 to your computer and use it in GitHub Desktop.
Find largest substring without repeating characters
This file contains hidden or 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
def find_substring(string): | |
""" Function that returns the longest | |
substring without repetition | |
""" | |
max_length = 0 | |
init_sub = -1 | |
letters_dict = {} | |
for idx, letter in enumerate(string): | |
if letter in letters_dict: | |
init_sub = max(init_sub, letters_dict[letter]) | |
max_length = max(max_length, idx - init_sub) | |
letters_dict[letter] = idx | |
return max_length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment