문제 링크 : https://leetcode.com/problems/minimum-domino-rotations-for-equal-row/description/?orderBy=most_votes
주어진 도미노의 tops 혹은 bottoms중 하나가 만약 같은 값으로 바꿀 수 있다면 가장 최소한의 rotate으로 바꾸어야하는 지 구하여라
일단 top 혹은 bottomdmㄹ 같은 값으로 만들 수 있는지 판단한 뒤 top/bottom 중 최소한의 경우로 같은 값을 만들 수 있는 걸 구한다
class Solution:
def minDominoRotations(self, tops: List[int], bottoms: List[int]) -> int:
for target in [tops[0],bottoms[0]]:
misssingT, missingB = 0,0
for i, d in enumerate(zip(tops, bottoms)):
top, bottom = d
if not(top == target or bottom == target):
break
if top != target:
misssingT +=1
if bottom != target:
missingB +=1
if i == len(tops)-1:
return min(misssingT, missingB)
return -1