LeetCode题解(1386):安排电影院座位(Python)
生活随笔
收集整理的這篇文章主要介紹了
LeetCode题解(1386):安排电影院座位(Python)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目:原題鏈接(中等)
標(biāo)簽:貪心算法、數(shù)組
| 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)) # 計(jì)算空行數(shù)量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總結(jié)
以上是生活随笔為你收集整理的LeetCode题解(1386):安排电影院座位(Python)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 三相电压型逆变器控制simulink
- 下一篇: 【问】登陆提示用户SA登陆失败