当前位置:网站首页>酷逼了 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
边栏推荐
猜你喜欢
清华教授发文劝退读博:我见过太多博士生精神崩溃、心态失衡、身体垮掉、一事无成!...
MUI as a mobile phone to return to the action bar
设计专业第一台笔记本 华硕灵耀Pro16 2022 新品首发超值入手
打破文件锁限制,以存储力量助力企业增长新动力
2.8K 120Hz touch dual-screen blessing Lingyao X dual-screen Pro 2022 makes the office without fear of imagination
第一次改开源中间件keycloak总个结
MySQL INTERVAL 关键字指南
02 es 集群搭建
MySQL [create and manage tables]
美国弗吉尼亚大学、微软 | Active Data Pattern Extraction Attacks on Generative Language Models(对生成语言模型的主动数据模式提取攻击)
随机推荐
AntDB数据库亮相24届高速展,助力智慧高速创新应用
请问nacos 连接mysql失败后会重新连接吗?
Use Canvas to implement mobile phone signature
eslint语法报错解决
如何有效地开发 Jmix 扩展组件
指针进阶(三)之指针与数组笔试题
ECCV 2022 | Poseur:你以为我是姿态估计,其实是目标检测哒
显示为弹出窗口是什么意思(电脑总是弹出广告)
shell 基础之函数编写
untiy Resorces目录动态加载资源
直播app开发,是优化直播体验不得不关注的两大指标
主流定时任务解决方案全横评
C#的DateTime帮助类
Convert tensor to image in pytorch
27英寸横置大屏+实体按键,全新探险者才是安全而合理的做法
【建议收藏】技术面必考题:多线程、多进程
C#的FTP帮助类
C#的DataTable帮助类
pytorch测试的时候为何要加上model.eval()?
kubelet node pressure eviction