Skip to content

Latest commit

 

History

History
29 lines (23 loc) · 892 Bytes

File metadata and controls

29 lines (23 loc) · 892 Bytes

Find missing and repeated values

Problem link

Solutions

Solution.py

# https://leetcode.com/problems/find-missing-and-repeated-values/

class Solution:
    def findMissingAndRepeatedValues(self, grid: List[List[int]]) -> List[int]:
        n = len(grid)
        nsq = n * n
        seen, missing = {}, (nsq * (nsq + 1)) // 2
        for row in grid:
            for x in row:
                if x in seen:
                    double = x
                else:
                    missing -= x
                    seen[x] = 1
        return [double, missing]

Tags