1868. Product of Two Run-Length Encoded Arrays

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1868

class Solution:
    def findRLEArray(
        self, encoded1: List[List[int]], encoded2: List[List[int]]
    ) -> List[List[int]]:
        res = []
        j = 0
        for vi, fi in encoded1:
            while fi:
                f = min(fi, encoded2[j][1])
                v = vi * encoded2[j][0]
                if res and res[-1][0] == v:
                    res[-1][1] += f
                else:
                    res.append([v, f])
                fi -= f
                encoded2[j][1] -= f
                if encoded2[j][1] == 0:
                    j += 1
        return res