Skip to content

Commit 89a2ada

Browse files
committed
Time: 0 ms (100%), Space: 25.6 MB (95.07%) - LeetHub
1 parent b362f75 commit 89a2ada

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Solution {
2+
public:
3+
vector<int> findMissingAndRepeatedValues(vector<vector<int>>& grid) {
4+
int both = 0;
5+
int n = grid[0].size();
6+
for (auto& i : grid) {
7+
for (auto& j : i) {
8+
both ^= j;
9+
}
10+
}
11+
for (int i = 1; i <= n * n; i++) {
12+
both ^= i;
13+
}
14+
int groupA = 0, groupB = 0;
15+
int lsb = both & -both;
16+
for (auto& i : grid) {
17+
for (auto& j : i) {
18+
if (j & lsb) groupA ^= j;
19+
else groupB ^= j;
20+
}
21+
}
22+
for (int i = 1; i <= n * n; i++) {
23+
if (i & lsb) groupA ^= i;
24+
else groupB ^= i;
25+
}
26+
27+
for (auto& i : grid) {
28+
for (auto& j : i) {
29+
if (j == groupA) {
30+
return {groupA, groupB};
31+
}
32+
}
33+
}
34+
return {groupB, groupA};
35+
}
36+
};

0 commit comments

Comments
 (0)