Skip to content

Commit 80cdb56

Browse files
authored
Create minimum-domino-rotations-for-equal-row.py
1 parent bfe1153 commit 80cdb56

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
import itertools
5+
6+
7+
class Solution(object):
8+
def minDominoRotations(self, A, B):
9+
"""
10+
:type A: List[int]
11+
:type B: List[int]
12+
:rtype: int
13+
"""
14+
intersect = reduce(set.__and__, [set(d) for d in itertools.izip(A, B)])
15+
if not intersect:
16+
return -1
17+
x = intersect.pop()
18+
return min(len(A)-A.count(x), len(B)-B.count(x))

0 commit comments

Comments
 (0)