File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
2965-find-missing-and-repeated-values Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 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+ };
You can’t perform that action at this time.
0 commit comments