Leetcode 1049 Solution
This article provides solution to leetcode question 1049 (minimum-domino-rotations-for-equal-row)
Access this page by simply typing in "lcs 1049" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/minimum-domino-rotations-for-equal-row
Solution
class Solution:
def minDominoRotations(self, A: List[int], B: List[int]) -> int:
s = {A[0], B[0]}
for i in range(1, len(A)):
s &= {A[i], B[i]}
ans = 1000000
for target in s:
for arr in [A, B]:
local_ans = 0
for v in arr:
if v != target:
local_ans += 1
ans = min(local_ans, ans)
return ans if ans != 1000000 else -1