日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

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

發布時間:2023/12/31 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LeetCode题解(1386):安排电影院座位(Python) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目:原題鏈接(中等)

標簽:貪心算法、數組

解法時間復雜度空間復雜度執行用時
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, Truefor j in info[i]:if j in choice1:b1 = Falseif j in choice2:b2 = Falseif j in choice3:b3 = Falseif b1 and b3:ans += 2elif b1 or b2 or b3:ans += 1return ans

總結

以上是生活随笔為你收集整理的LeetCode题解(1386):安排电影院座位(Python)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。