LeetCode题解(1386):安排电影院座位(Python)

LeetCode题解(1386):安排电影院座位(Python),第1张

概述题目:原题链接(中等)标签:贪心算法、数组解法时间复杂度空间复杂度执行用时Ans1(Python)O(R)

题目:原题链接(中等)

标签:贪心算法、数组

解法时间复杂度空间复杂度执行用时
Ans 1 (Python) O ( R ) O(R) O(R) O ( R ) O(R) O(R)144ms (41.56%)
Ans 2 (Python)
Ans 3 (Python)

解法一:

class Solution:    def maxnumberOfFamilIEs(self, n: int, reservedSeats: List[List[int]]) -> int:        info = collections.defaultdict(List)        for i, j in reservedSeats:            info[i].append(j)        ans = (10 // 4) * (n - len(info))  # 计算空行数量        for i in info:            choice1 = {2, 3, 4, 5}            choice2 = {4, 5, 6, 7}            choice3 = {6, 7, 8, 9}            b1, b2, b3 = True, True, True            for j in info[i]:                if j in choice1:                    b1 = False                if j in choice2:                    b2 = False                if j in choice3:                    b3 = False            if b1 and b3:                ans += 2            elif b1 or b2 or b3:                ans += 1        return ans
总结

以上是内存溢出为你收集整理的LeetCode题解(1386):安排电影院座位(Python)全部内容,希望文章能够帮你解决LeetCode题解(1386):安排电影院座位(Python)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1189399.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存