1820. Maximum Number of Accepted Invitations

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

On This Page

LeetCode problem 1820

class Solution:
    def maximumInvitations(self, grid: List[List[int]]) -> int:
        def find(i):
            for j, v in enumerate(grid[i]):
                if v and j not in vis:
                    vis.add(j)
                    if match[j] == -1 or find(match[j]):
                        match[j] = i
                        return True
            return False

        m, n = len(grid), len(grid[0])
        match = [-1] * n
        res = 0
        for i in range(m):
            vis = set()
            res += find(i)
        return res