当前位置:网站首页>酷逼了 Pathetic Dog 第 304 场周赛
酷逼了 Pathetic Dog 第 304 场周赛
2022-08-01 16:23:00 【Yake1965】
酷逼了 Pathetic Dog 第 304 场周赛
Pathetic Dog 全球排名第一
参考大神题解按自己的习惯改一些变量名
6132. 使数组中所有元素都等于零
class Solution:
def minimumOperations(self, nums):
return len(set(x for x in nums if x > 0))
6133. 分组的最大数量
尽然和分数没有关系,简化了大神的题解。
class Solution:
def maximumGroups(self, grades: List[int]) -> int:
pre = cnt = res = 0
for i in range(len(grades)):
cnt += 1
if cnt > pre: # 比前一个个数大更新
res += 1
pre = cnt
cnt = 0
return res
6134. 找到离给定两个节点最近的节点
class Solution:
def closestMeetingNode(self, edges: List[int], node1: int, node2: int) -> int:
node1_dis = [-1] * len(edges)
cur, dis = node1, 0
while cur != -1:
if node1_dis[cur] != -1: break
node1_dis[cur] = dis
cur = edges[cur]
dis += 1
node2_dis = [-1] * len(edges)
cur, dis = node2, 0
while cur != -1:
if node2_dis[cur] != -1: break
node2_dis[cur] = dis
cur = edges[cur]
dis += 1
ans, best = -1, inf
for i, (j, k) in enumerate(zip(node1_dis, node2_dis)):
if j == -1 or k == -1: continue
if max(j, k) < best:
best = max(j, k)
ans = i
return ans
6135. 图中的最长环
class Solution:
def longestCycle(self, edges: List[int]) -> int:
ans = -1
vis = set()
for i in range(len(edges)):
cnt = 0
position = {
}
while i != -1 and i not in vis:
position[i] = cnt
vis.add(i)
i = edges[i]
cnt += 1
if i != -1 and i in position:
ans = max(ans, cnt - position[i])
return ans
边栏推荐
猜你喜欢
蚂蚁首次披露核心基础软件技术开源版图
DOM series of touch screen events
Ant discloses the open source layout of core basic software technology for the first time
Use Canvas to implement mobile phone signature
5年测试,只会功能要求17K,功能测试都敢要求这么高薪资了?
阿里官方 Redis 开发规范
华盛顿大学、Allen AI 等联合 | RealTime QA: What's the Answer Right Now?(实时 QA:现在的答案是什么?)
MySQL INTERVAL 关键字指南
会议OA项目(六)--- (待开会议、历史会议、所有会议)
HashCode technology insider interview must ask
随机推荐
Winform的消息提示框帮助类
Shell basic function writing
打破文件锁限制,以存储力量助力企业增长新动力
【建议收藏】技术面必考题:多线程、多进程
每日优鲜大败局
【Unity,C#】哨兵射线触发器模板代码
五分钟带你上手ShardingJDBC实现MySQL分库分表
请问nacos 连接mysql失败后会重新连接吗?
OneFlow源码解析:Op、Kernel与解释器
设计专业第一台笔记本 华硕灵耀Pro16 2022 新品首发超值入手
pynlpir更新license Error: unable to fetch newest license解决方案
TiFlash 存储层概览
js to determine whether it is a pc or a mobile terminal (including ipad)
Rancher 部署 DataKit 最佳实践
重庆银河证券股票开户安全吗,是正规的证券公司吗
How to Efficiently Develop Jmix Extension Components
Convert tensor to image in pytorch
Synchronized原理
暑气渐敛,8月让我们开源一夏!
MySQL INTERVAL 关键字指南