1738. Find Kth Largest XOR Coordinate Value

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

Содержание

LeetCode problem 1738

class Solution:
    def kthLargestValue(self, matrix: List[List[int]], k: int) -> int:
        m, n = len(matrix), len(matrix[0])
        s = [[0] * (n + 1) for _ in range(m + 1)]
        res = []
        for i in range(m):
            for j in range(n):
                s[i + 1][j + 1] = s[i + 1][j] ^ s[i][j + 1] ^ s[i][j] ^ matrix[i][j]
                res.append(s[i + 1][j + 1])
        return nlargest(k, res)[-1]