leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1007.cpp (564B)


      1 class Solution {
      2   public:
      3     int minDominoRotations(const vector<int> &tops, const vector<int> &bottoms) {
      4         const int n = size(tops);
      5         int up[7] = {0}, down[7] = {0}, both[7] = {0};
      6 
      7         for (int i = 0; i < n; i++) {
      8             if (tops[i] == bottoms[i])
      9                 both[tops[i]]++;
     10             else
     11                 up[tops[i]]++, down[bottoms[i]]++;
     12         }
     13 
     14         for (int i = 1; i <= 6; i++) {
     15             if (up[i] + down[i] != n - both[i]) continue;
     16             return min(up[i], down[i]);
     17         }
     18 
     19         return -1;
     20     }
     21 };