Distinct Words
Easy · rating 950 · hashing, strings
Read a line of words separated by spaces. Print how many distinct words it contains (case-sensitive).
Editorial
Distinct Words counts how many unique words appear in a line (case-sensitive). Split into words and put them in a set — its size is the answer.
print(len(set(line.split())))Complexity
Time: O(n). Space: O(n).