Count Distinct Elements

Given an integer array nums, return the number of distinct values present in the array. Equal values contribute one distinct value regardless of how many…

Given an integer array `nums`, return the number of distinct values present in the array. Equal values contribute one distinct value regardless of how many times they occur.

- `1 <= nums.length <= 100` - `-10^9 <= nums[i] <= 10^9` - The interactive visualizer accepts at most 12 values; longer valid arrays are execution-only.

Example 1: input nums = [4,4,2,7,2]; output 3. The distinct values are 4, 2, and 7.

Example 2: input nums = [5,5,5]; output 1. Only the value 5 is present.

Category: Arrays & Hashing. Topic: arrays. Difficulty: Easy. Patterns: hashing.