当前位置:网站首页>leetcode 1791. Find the central node of the star chart
leetcode 1791. Find the central node of the star chart
2022-07-21 09:56:00 【Paramecium drinking milk】
Use a dictionary to count the degree of each node , The central node is degree n-1 The node of
class Solution:
def findCenter(self, edges: List[List[int]]) -> int:
dic = {
}
for i, j in edges:
dic[i] = 1 if i not in dic else dic[i]+1
dic[j] = 1 if j not in dic else dic[j]+1
n = max(dic)
for i in dic:
if dic[i] == n-1:
return i
边栏推荐
猜你喜欢
随机推荐
[composition principle V system bus]
ggplot2可视化分面图(faceting)、可视化分面山脊图(facetted ridgeline plot with facet_wrap)、并自定义分面图标题框(title box)的背景色
js遍历字符串
基于dpdk基础知识整理-01
Write multiple main in the source file of vs stdio project
U-Net: Convolutional Networks for Biomedical Image Segmentation
C语言力扣第九题之回文数。两指针数组遍历法
Qt tablewidget判断某行是否被选中并获取选中行的数据
【论文翻译】TNT: Target-driveN Trajectory Prediction
Grpc MagicOnion库 之 客户端和服务端 (案例版)
2022 Henan Mengxin League game (2)
js 数组reduce方法求和 求最大值 求最小值方法
【求助】基于Ascend910的MindSpore训练无法复现GPU上的模型效果
【HMS Core】【FAQ】【Health Kit】运动健康服务常见错误码合集 403、401、1001、20023
U-Net: Convolutional Networks for Biomedical Image Segmentation
TransData算子是什么功能的,能否优化性能
[Bert] model return value analysis
c语言力扣第二题之链表两数相加。遍历法
实现一个《头像循环轮播控件》
GUI 基础应用