nikunjsoni

1007

Jun 28th, 2021
85
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     int minDominoRotations(vector<int>& A, vector<int>& B) {
  4.         vector<int> countA(7), countB(7), same(7);
  5.         int n = A.size();
  6.         for (int i = 0; i < n; ++i) {
  7.             countA[A[i]]++;
  8.             countB[B[i]]++;
  9.             if (A[i] == B[i])
  10.                 same[A[i]]++;
  11.         }
  12.         for (int i  = 1; i < 7; ++i)
  13.             if (countA[i] + countB[i] - same[i] == n)
  14.                 return n - max(countA[i], countB[i]);
  15.         return -1;
  16.     }
  17. };
RAW Paste Data