Skip to content

Commit 78cd278

Browse files
authored
Create find-occurrences-of-an-element-in-an-array.py
1 parent 3e4de97 commit 78cd278

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
# array
5+
class Solution(object):
6+
def occurrencesOfElement(self, nums, queries, x):
7+
"""
8+
:type nums: List[int]
9+
:type queries: List[int]
10+
:type x: int
11+
:rtype: List[int]
12+
"""
13+
lookup = [i for i, y in enumerate(nums) if y == x]
14+
return [lookup[q-1] if q-1 < len(lookup) else -1 for q in queries]

0 commit comments

Comments
 (0)