3810. Minimum Operations to Reach Target Array
You are given two integer arrays
numsandtarget, each of lengthn, wherenums[i]is the current value at indexiandtarget[i]is the desired value at indexi.You may perform the following operation any number of times (including zero):
- Choose an integer value
x- Find all maximal contiguous segments where
nums[i] == x(a segment is maximal if it cannot be extended to the left or right while keeping all values equal tox)- For each such segment
[l, r], update simultaneously:
nums[l] = target[l], nums[l + 1] = target[l + 1], ..., nums[r] = target[r]Return the minimum number of operations required to make
numsequal totarget.
1 | class Solution { |