I can think of sorting them and then going over each element one by one but this is nlogn. Is there a linear method to count distinct elements in a list?
You can adapt this extremely cool O(n)-time and O(1)-space in-place algorithm for removing duplicates to the task of counting distinct values -- simply count the number of values equal to the sentinel value in a final O(n) pass, and subtract that from the size of the list.