Created
January 28, 2016 21:12
-
-
Save pyrofolium/b43b659b4c46ff5fc61e 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
def longest_non_repeating_string(input_str): | |
repeated_chars = {} | |
longest_string = "" | |
current_string = "" | |
for char in input_str: | |
if char in repeated_chars: | |
current_string = "" | |
repeated_chars = {} | |
current_string += char | |
repeated_chars[char] = True | |
if len(current_string) > len(longest_string): | |
longest_string = current_string | |
return longest_string | |
print longest_non_repeating_string("broadband") | |
print longest_non_repeating_string("hello abcdefhijkl") | |
print longest_non_repeating_string("madam am i") | |
print longest_non_repeating_string("hello worldfair") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment