LeetCode #2657

Find the Prefix Common Array of Two Arrays

1개의 풀이 · C++

문제 원문 보기 ↗

SOLUTION INFO

C++ · main.cpp

main.cpp
class Solution {
public:
    vector<int> findThePrefixCommonArray(vector<int>& A, vector<int>& B) {
        long long l = 0, r = 0;
        int N = (int)A.size();
        for(int i = 0; i < N; ++i) {
            l |= 1LL << A[i];
            r |= 1LL << B[i];
            A[i] = __builtin_popcountll(l & r);
        }
        return A;
    }
};

SOLUTION DESCRIPTION

풀이 설명

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