当前位置:网站首页>LeetCode 1791. Find the central node of the star chart
LeetCode 1791. Find the central node of the star chart
2022-06-24 04:52:00 【freesan44】
subject
There is an undirected Star type chart , from n A number from 1 To n Node composition of . The star graph has a center node , And there is n - 1 The edges connect the central node to each other .
Here's a two-dimensional array of integers edges , among edgesi = ui, vi At the node ui and vi There is an edge between . Please find out and return to edges The center node of the star graph represented by .
Example 1: Input :edges = [[1,2],[2,3],[4,2]] Output :2 explain : As shown in the figure above , node 2 Connected to every other node , So node 2 It's the central node . Example 2: Input :edges = [[1,2],[5,1],[1,3],[1,4]] Output :1 ```
Tips :
3 <= n <= 105
edges.length == n - 1
edgesi.length == 2
1 <= ui, vi <= n
ui != vi
The title data gives edges Represents an effective star graph
Their thinking
class Solution:
def findCenter(self, edges: List[List[int]]) -> int:
resList = []
# Disassemble all the arrays to form one List, And then use Counter inductive , Find the quantity as n Of
for i in edges:
resList += i
# print(resList)
from collections import Counter
count = Counter(resList)
for (key, val) in count.items():
# print(key,val)
# print(len(edges)-1)
if val == (len(edges)):
return key
return 0
if __name__ == '__main__':
edges = [[1,2],[2,3],[4,2]]
ret = Solution().findCenter(edges)
print(ret)边栏推荐
- After purchasing Tencent ECs, how to solve packet loss in Internet access?
- Introduction to the "penetration foundation" cobalt strike Foundation_ Cobalt strike linkage msfconsole
- Getattribute return value is null
- Training course of mixed accuracy from simple to deep
- Advanced authentication of uni app [Day12]
- Collagenase -- four types of crude collagenase from Worthington
- Weak current engineer, 25g Ethernet and 40g Ethernet: which do you choose?
- 外网访问svn服务器(外网访问部署在云上的svn服务器)
- uni-app进阶之认证【day12】
- Application and related research of Worthington elastase
猜你喜欢

Abnova peptide design and synthesis solutions

Abnova多肽设计和合成解决方案

SAP MTS/ATO/MTO/ETO专题之七:ATO模式1 M+M模式策略用82(6892)

Loss and optimization of linear regression, machine learning to predict house prices

Abnova fluorescence in situ hybridization (FISH) probe solution
Summary of Android interview questions in 2020 (intermediate)

Abnova membrane protein lipoprotein solution

Apipost interface assertion details

Introduction to the "penetration foundation" cobalt strike Foundation_ Cobalt strike linkage msfconsole

梯度下降法介紹-黑馬程序員機器學習講義
随机推荐
How to operate ECs and what types of system configuration schemes can be supported
IP and traffic reconciliation tool networktrafficview
apipost接口断言详解
阿里云新一代云计算体系架构 CIPU 到底是啥?
Mini web framework: adding routes in decorator mode | dark horse programmer
What is the new generation cloud computing architecture cipu of Alibaba cloud?
Recognize workplus again, not only im but also enterprise mobile application management expert
2022年二级造价工程师备考攻略,你准备好了吗?
Let children learn the application essence of steam Education
Apipost interface assertion details
What are the advantages of ECS? Is ECS better than VM?
Introduction à la méthode de descente par Gradient - document d'apprentissage automatique pour les programmeurs de chevaux noirs
oracle数据库提示无操作权限的问题
Physicochemical properties and specificity of Worthington trypsin
How to enlarge the ECS page? How to select ECS instance specifications?
阿里云混合云首席架构师张晓丹:政企混合云技术架构的演进和发展
Spirit breath development log (15)
How does ECS build websites? Is it troublesome for ECs to build websites?
Abnova膜蛋白脂蛋白体解决方案
Summary of Android interview questions in 2020 (elementary)