Class Solution
-
- All Implemented Interfaces:
public final class Solution
2965 - Find Missing and Repeated Values.
Easy
You are given a 0-indexed 2D integer matrix
grid
of sizen * n
with values in the range <code>1, n<sup>2</sup></code>. Each integer appears exactly once excepta
which appears twice andb
which is missing. The task is to find the repeating and missing numbersa
andb
.Return a 0-indexed integer array
ans
of size2
whereans[0]
equals toa
andans[1]
equals tob
.Example 1:
Input: grid = [1,3,2,2]
Output: 2,4
Explanation: Number 2 is repeated and number 4 is missing so the answer is 2,4.
Example 2:
Input: grid = [9,1,7,8,9,2,3,4,6]
Output: 9,5
Explanation: Number 9 is repeated and number 5 is missing so the answer is 9,5.
Constraints:
2 <= n == grid.length == grid[i].length <= 50
1 <= grid[i][j] <= n * n
For all
x
that1 <= x <= n * n
there is exactly onex
that is not equal to any of the grid members.For all
x
that1 <= x <= n * n
there is exactly onex
that is equal to exactly two of the grid members.For all
x
that1 <= x <= n * n
except two of them there is exatly one pair ofi, j
that0 <= i, j <= n - 1
andgrid[i][j] == x
.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntArray
findMissingAndRepeatedValues(Array<IntArray> grid)
-
-
Method Detail
-
findMissingAndRepeatedValues
final IntArray findMissingAndRepeatedValues(Array<IntArray> grid)
-
-
-
-