Unique Elements

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 5.0s
Memory limit: 64M

Author:
Problem type

Given a list of N (1N30000) positive integers less than or equal to 109, print out how many distinct numbers exist.

Input Specification

The first line will contain the integer N. The next N lines will contain an element in the list.

Output Specification

One integer: the number of distinct elements in the given list.

Sample Input 1

Copy
2
1
2

Sample Output 1

Copy
2

Sample Input 2

Copy
4
1
2
2
5

Sample Output 2

Copy
3

Comments


  • 4
    echofox  commented on July 22, 2018, 12:22 a.m. edit 3

    this is so sad

    e


  • 4
    Oppenheimer  commented on Oct. 1, 2014, 9:31 p.m.

    You one-liners make me feel bad...


    • 2
      Xyene  commented on Oct. 2, 2014, 2:08 a.m. edited

      Hint: sets have very fast O(1) in checks, whereas lists have very slow O(N) in checks. Your solution will probably pass if you use a set, but you may have to combine your two for loops into one.