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)


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