赞
踩
目录
- class Solution:
- def distributeCandies(self, candyType: List[int]) -> int:
- # 模拟
- # 在n // 2和不同种类数中选择最小值
- return min(len(candyType) // 2, len(set(candyType)))
- class Solution:
- def minimumChairs(self, s: str) -> int:
- ans = 0
- cnt = 0
- for c in s:
- if c == 'E':
- cnt += 1
- ans = max(ans, cnt)
- else:
- cnt -= 1
- return ans
days范围太大了。
- class Solution:
- def countDays(self, days: int, meetings: List[List[int]]) -> int:
- # 差分
- ans = 0
- nums = [0] * (days + 1)
- for a, b in meetings:
- nums[a - 1] += 1
- nums[b] -= 1
- cur = 0
- for i in range(days):
- cur += nums[i]
- if cur == 0:
- ans += 1
- return ans
来自灵神题解(. - 力扣(LeetCode))。
- class Solution:
- def countDays(self, days: int, meetings: List[List[int]]) -> int:
- # 合并数组
- meetings.sort(key = lambda p: p[0])
- start, end = 1, 0
- for s, e in meetings:
- if s > end: # 新的区间
- days -= end - start + 1 # 更新
- start = s
- end = max(end, e)
- days -= end - start + 1 # 更新最后一个区间
- return days
完
感谢你看到这里!一起加油吧!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。