当前位置:网站首页>酷逼了 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
边栏推荐
猜你喜欢

华盛顿大学、Allen AI 等联合 | RealTime QA: What's the Answer Right Now?(实时 QA:现在的答案是什么?)

每日优鲜大败局

Vulnhub靶机:HARRYPOTTER_ NAGINI

Using Canvas to achieve web page mouse signature effect

ESP8266-Arduino编程实例-74HC595位移寄存驱动

沈腾拯救暑期档
MySQL INTERVAL Keyword Guidelines

使用Canvas 实现手机端签名

IronOS, an open source system for portable soldering irons, supports a variety of portable DC, QC, PD powered soldering irons, and supports all standard functions of smart soldering irons

设计专业第一台笔记本 华硕灵耀Pro16 2022 新品首发超值入手
随机推荐
Spark: Cluster Computing with Working Sets
IronOS, an open source system for portable soldering irons, supports a variety of portable DC, QC, PD powered soldering irons, and supports all standard functions of smart soldering irons
Spark: Cluster Computing with Working Sets
火花:集群计算工作集
Eslint syntax error is solved
shell 基础之函数编写
OpenCV-resize函数「建议收藏」
【建议收藏】技术面必考题:多线程、多进程
Flink - SQL can separate a certain parallelism of operator node configuration?
90后的焦虑,被菜市场治好了
ESP8266-Arduino编程实例-MLX90614红外测温传感器驱动
pynlpir更新license Error: unable to fetch newest license解决方案
Rancher 部署 DataKit 最佳实践
我的新书销量1万册了!
11 一发布就发布一系列系列
比对软件-blastN结果详解
【无标题】
1个月写900多条用例,2线城市年薪33W+的测试经理能有多卷?
14年测试人最近的面试经历,值得借鉴√
DOM series of touch screen events