Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Given a string s, determine whether it has all unique characters.
- Example 1
- Input
- s = "abcde"
- Output
- True
- '''
- def solve(s):
- unique = list()
- for i in range(len(s)):
- if s[i] not in unique:
- unique.append(s[i])
- # Create a dictionary
- dictionary = dict()
- for char in unique:
- dictionary[char] = 0
- for i in range(len(s)):
- for j in range(len(unique)):
- if s[i] == unique[j]:
- dictionary[s[i]] += 1
- # Now, we have the dictionary and the appearance of each unique letter
- print(dictionary)
- for key in dictionary:
- if dictionary[key] != 1:
- return False
- return True
- # MAIN FUNCTION
- print(solve("abcde"))
- print(solve("abcdef"))
- print(solve("abcdeeeeea"))
- print(solve("abcdeAAd"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement