0
/ 1.0
Problem Description
Write a method countDistinct
that takes an array of integers and returns the count of distinct (unique) numbers...
Write a method countDistinct
that takes an array of integers and returns the count of distinct (unique) numbers present in the array.
Method Signature:
public int countDistinct(int[] nums)
TreeSet<Integer>
as the class to store the set.TreeSet
will automatically handle duplicate values, so you only need to focus on inserting numbers.Set
documentation is available online.TreeSet
documentation is available online.Examples:
countDistinct({1, 2, 3, 2, 4, 1}) -> 4
countDistinct({7, 7, 7, 7, 7, 7}) -> 1
Your feedback will appear here when you check your answer.