当前位置:网站首页>LeetCode Algorithm 1791. 找出星型图的中心节点
LeetCode Algorithm 1791. 找出星型图的中心节点
2022-06-12 01:38:00 【Alex_996】
题目链接:1791. 找出星型图的中心节点
Ideas
算法:计数
数据结构:图
思路:中心节点其实就是度为n-1的节点,所以我们可以用一个计数器统计所有节点的度,如果度为n-1,那么它就是中心节点。题目的输入中并没有给定n,所以这个是自己去找的,而且题目给出的是一个二维数组,不好操作,最好可以将其拉平为一维数组,参考文章:将不规则的Python多维数组拉平到一维。
Code
Python
class Solution:
def findCenter(self, edges: List[List[int]]) -> int:
from itertools import chain
from collections import Counter
array = list(chain(*edges))
n = max(array)
cnt = Counter(array)
for key, val in cnt.items():
if val == n - 1:
return key
边栏推荐
- [project training] verification notes
- Basic use of MATLAB
- 只会基础的功能测试的我,被炒鱿鱼了····
- Forecast report on market demand and future prospect of cvtf industry of China's continuously variable transmission oil
- The annual salary of testers in large factories ranges from 300000 to 8K a month. Roast complained that the salary was too low, but he was ridiculed by netizens?
- Industry competition analysis and investment scale research report of global and Chinese micro potato industry 2022-2028
- Global and Chinese lutetium oxide powder industry investigation and analysis and Investment Strategy Research Report 2022-2028
- Analysis report on operation trends and development strategies of global and Chinese plastic adhesive industry 2022-2028
- Simulated 100 questions and simulated examination for safety management personnel of metal and nonmetal mines (small open pit quarries) in 2022
- [n32g457] remote monitoring of graffiti cloud based on RT thread and n32g457
猜你喜欢

我在某大厂做软件测试工程师的《一天完整工作流程》

I'm fired because I can only test basic functions····

jmeter 性能测试用 csv,这个坑有些扯蛋

Huawei, this is too strong

Matlab 基础应用02 wind 股票数据介绍和使用案例:

Given a project, how will you conduct performance testing?

Matlab 基础04 - 冒号Colon operator “:”的使用和复杂应用详析

华为联运游戏或应用审核驳回:应用检测到支付serviceCatalog:X6

In depth description of Weibull distribution (2) meaning of parameters and formulas

How to access the traifik proxy dashboard using the rancher desktop
随机推荐
Henan Zhongchuang - from cloud to edge, how edge computing enables data centers
给你一个项目,你将如何开展性能测试工作?
MATLAB basic application 02 wind stock data introduction and use case:
2022年金属非金属矿山(小型露天采石场)安全管理人员考试模拟100题及模拟考试
Markov networks and conditional random fields
聯調這夜,我把同事打了...
Agile v.s. Waterfall
C dynamically calls the static library generated by go
PCA from 0 to 1
Set up NFT blind box mall system | customized development of NFT mall software
西南林业大学“西林链”通过工信部电子标准院功能测试 | FISCO BCOS案例
Article 7: Design of multifunctional intelligent trunk following control system | undergraduate graduation project - [module device selection, list and data]
pip运行报错:Fatal error in launcher: Unable to create process using
kmeans从0到1
Global and Chinese lutetium oxide powder industry investigation and analysis and Investment Strategy Research Report 2022-2028
感知机从0到1
Blue Bridge Cup - 2012b Group real question 3 specific drinking capacity
Three line code solution - Maximum sub segment and - DP
Weibull Distribution韦布尔分布的深入详述(1)原理和公式
[project training] wechat official account template message push