1.1 Implement an algorithm to determine if a string has all unique characters. Whatif you cannot use additional data structures?
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 uniqueString(str): | |
"Return True if the string has all unique characters." | |
allChar = [] | |
for i in range(256): | |
allChar.append(True) | |
for char in str: | |
if(allChar[ord(char)]): | |
allChar[ord(char)] = False | |
else: | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tip: you could save the file with name like CareerCup1.1.py such that it highlights the grammar keywords in your code:)