leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2661.cpp (664B)
0 class Solution {
1 public:
2 int firstCompleteIndex(const vector<int> &arr, const vector<vector<int>> &mat) const {
3 static tuple<int, int> mapping[100001];
4 static int rc[100001][2];
5 const int n = size(mat), m = size(mat[0]);
7 memset(rc, 0x00, 8 * size(arr));
9 for (int i = 0; i < n; i++) {
10 for (int j = 0; j < m; j++) {
11 mapping[mat[i][j]] = {i, j};
12 }
13 }
15 for (int i = 0; i < size(arr); i++) {
16 const auto [c, r] = mapping[arr[i]];
17 if (++rc[r][0] == n) return i;
18 if (++rc[c][1] == m) return i;
19 }
21 return -1;
22 }
23 };