← 返回 waymo 的题目列表Count Elements in an Array
类型:online_judge
Algorithm Problem: Count Element Occurrences
Given an integer array nums, write a function to count the occurrences of each element in the array. The output should be a dictionary where keys are elements and values are their counts.
Input
List of integers nums with size between [1, 10^5].
Output
A dictionary representing the count of each element in the array.
Example
Input:
[2, 3, 3, 2, 2, 4, 3]
Output:
{2: 3, 3: 3, 4: 1}
Example
Input
[1, 2, 2, 3, 3, 3, 4]