2672. Number of Adjacent Elements With the Same Color
There is a 0-indexed array
nums
of lengthn
. Initially, all elements are uncolored (has a value of0
).You are given a 2D integer array
queries
wherequeries[i] = [indexi, colori]
.For each query, you color the index
indexi
with the colorcolori
in the arraynums
.Return an array
answer
of the same length asqueries
whereanswer[i]
is the number of adjacent elements with the same color after theith
query.More formally,
answer[i]
is the number of indicesj
, such that0 <= j < n - 1
andnums[j] == nums[j + 1]
andnums[j] != 0
after theith
query.
1 | class Solution { |