1981. Minimize the Difference Between Target and Chosen Elements

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1981

class Solution:
    def minimizeTheDifference(self, mat: List[List[int]], target: int) -> int:
        f = {0}
        for row in mat:
            f = set(a + b for a in f for b in row)
        return min(abs(v - target) for v in f)