Last active
August 29, 2015 14:02
-
-
Save monkerek/f008f983280c2daf755d to your computer and use it in GitHub Desktop.
CC1.1
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
# idea: sort the string such that same characters sit together, then traverse the string one by one | |
# time complexity: O(NlogN)? depends on sorting alg. | |
# space complexity: O(1) | |
class Solution: | |
def UniqueChar(self, string): | |
if string == '': | |
return True | |
string = sorted(string) | |
prev = string[0] | |
for char in string[1:]: | |
if char == prev: | |
return False | |
prev = char | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sort it first, terrific idea!