LeetCode题解(0822):翻转卡片游戏(Python)

阅读 53

2022-02-24


题目:​​原题链接​​(中等)

标签:哈希表

解法

时间复杂度

空间复杂度

执行用时

Ans 1 (Python)

O ( N )

O ( N )

140ms (24.62%)

Ans 2 (Python)

Ans 3 (Python)

解法一:

class Solution:
def flipgame(self, fronts: List[int], backs: List[int]) -> int:
same = {fronts[i] for i in range(len(fronts)) if fronts[i] == backs[i]}
ans = 2001
for x in itertools.chain(fronts, backs):
if x not in same:
ans = min(ans, x)
return ans if ans != 2001 else 0


精彩评论(0)

0 0 举报