This commit is contained in:
parent
c58936690d
commit
a0c6abb2f2
1 changed files with 21 additions and 0 deletions
21
easy/find_missing_and_repeated_values.py
Normal file
21
easy/find_missing_and_repeated_values.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# https://leetcode.com/problems/find-missing-and-repeated-values
|
||||
|
||||
from typing import List
|
||||
|
||||
class Solution:
|
||||
def findMissingAndRepeatedValues(self, grid: List[List[int]]) -> List[int]:
|
||||
result: List[int] = []
|
||||
counts = {}
|
||||
n = len(grid) ** 2
|
||||
expected_sum = n * (n + 1) // 2
|
||||
actual_sum = 0
|
||||
for row in grid:
|
||||
for val in row:
|
||||
actual_sum += val
|
||||
if val in counts:
|
||||
result.append(val)
|
||||
else:
|
||||
counts[val] = 1
|
||||
result.append(result[0] - (actual_sum - expected_sum))
|
||||
return result
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue