Skip to content

Latest commit

 

History

History
25 lines (23 loc) · 701 Bytes

822.md

File metadata and controls

25 lines (23 loc) · 701 Bytes

822. Card Flipping Game

Solution 1 (time O(n), space O(1))

class Solution(object):
    def flipgame(self, fronts, backs):
        """
        :type fronts: List[int]
        :type backs: List[int]
        :rtype: int
        """
        n = len(fronts)
        same = set()
        for i in range(n):
            if fronts[i] == backs[i]:
                same.add(fronts[i])
        ans = float("inf")
        for i in range(n):
            if fronts[i] not in same and fronts[i] < ans:
                ans = fronts[i]
            if backs[i] not in same and backs[i] < ans:
                ans = backs[i]
        return ans if ans != float("inf") else 0