Bob has an array of � n integers. Output the number of distinct values in the array . Input The first input line has an integer � n: the number of values. The second line has � n integers � 1 , � 2 , … , � � x 1 ,x 2 ,…,x n . Output Print one integers: the number of distinct values. Constraints 1 ≤ � ≤ 2 ⋅ 1 0 5 1≤n≤2⋅10 5 1 ≤ � � ≤ 1 0 9 1≤x i ≤10 9
时间: 2024-01-06 11:03:16 浏览: 73
Array_Of_Int.rar_The Request
This is a simple problem that can be solved using a hash set. You can iterate through the array and add each element to the hash set. After iterating through the entire array, the size of the hash set will give you the number of distinct values in the array. Here's some sample code in Python:
```
n = int(input())
arr = list(map(int, input().split()))
distinct = set()
for x in arr:
distinct.add(x)
print(len(distinct))
```
This code reads in the input, iterates through the array, adds each element to the hash set, and then prints out the size of the hash set.
阅读全文