Minimum Domino Rotations For Equal Row LeetCode solution in Python

1
class Solution:
2
def minDominoRotations(self, tops: List[int], bottoms: List[int]) -> int:
3
sames = [tops[i] for i in range(len(tops)) if tops[i] == bottoms[i]]
4

5
same_count = collections.Counter(sames)
6
bottom_count = collections.Counter(bottoms)
7
top_count = collections.Counter(tops)
8

9
for n in range(1, 7):
10
if bottom_count[n] + top_count[n] - same_count[n] == len(tops):
11
return min(bottom_count[n], top_count[n]) - same_count[n]
12

13
return -1

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0