Count occurrences
Standard · Write code · about 6 min
Given an array of integers nums in any order and a target, return how many cells are equal to target.
Example 1
Input:
[[4,7,4,1,9,4,2],4]
Output:
3
Example 2
Input:
[[1,2,3],5]
Output:
0
5 does not appear.
Constraints
- 0 ≤ nums.length ≤ 10,000
- -10,000 ≤ nums[i], target ≤ 10,000
Learn the idea first: Linear search, a visual lesson.
More Linear search problems
- Index of target Warm-up
- Last index of target Standard
- Trace a linear scan Standard
- Search with a sentinel Challenge