Last active
July 13, 2020 05:41
-
-
Save shaunhyp57/27e62c6525d8e150d98d63c4ab0a9fae to your computer and use it in GitHub Desktop.
Cracking the Coding Interview, 6th Ed., Chapter 1 Question 1: Is Unique - using dictionaries, python solution
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
# using dictionary | |
# complexity: | |
# time - O(n) | |
# space - O(n) | |
def dict_is_unique(input_string): | |
unique = {} | |
for c in input_string: | |
if c in unique: | |
return False | |
else: | |
unique[c] = 1 | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment