LeetCode #2661

First Completely Painted Row or Column

1개의 풀이 · C++

문제 원문 보기 ↗

SOLUTION INFO

C++ · main.cpp

main.cpp
class Solution {
public:
    int firstCompleteIndex(vector<int>& arr, vector<vector<int>>& mat) {
        int N = (int)mat.size();
        int M = (int)mat[0].size();
        vector<int> chk_row(M), chk_col(N);
        vector<pair<int, int>> rindex(arr.size() + 1);
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < M; ++j) {
                rindex[mat[i][j]] = make_pair(i, j);
            }
        }
        int answer = -1;
        for(const int &value: arr) {
            auto [y, x] = rindex[value];
            ++ answer;
            if(++ chk_row[x] == N) break;
            if(++ chk_col[y] == M) break;
        }
        return answer;
    }
};

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.