当前位置:网站首页>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)边栏推荐
- Introduction to C language custom types (structure, enumeration, union, bit segment)
- Summary of Android interview questions in 2020 (intermediate)
- Powerbi - for you who are learning
- Worthington胰蛋白酶的物化性质及特异性
- How to build a website for ECS is the price of ECS very expensive
- SAP mts/ato/mto/eto topic 10: ETO mode q+ empty mode unvalued inventory policy customization
- 2020年Android面试题汇总(中级)
- 外网访问svn服务器(外网访问部署在云上的svn服务器)
- 重新认识WorkPlus,不止IM即时通讯,是企业移动应用管理专家
- 2020年Android面试题汇总(初级)
猜你喜欢

The official overclocking tool of Intel XTU supports win11 22h2 and 13th generation core Raptor Lake processors
Advanced authentication of uni app [Day12]

Idea creates a servlet and accesses the 404 message

SAP mts/ato/mto/eto topic 10: ETO mode q+ empty mode unvalued inventory policy customization

让孩子们学习Steam 教育的应用精髓

What is the data center

Final summary of freshman semester (supplement knowledge loopholes)

梯度下降法介紹-黑馬程序員機器學習講義

重新认识WorkPlus,不止IM即时通讯,是企业移动应用管理专家

『渗透基础』Cobalt Strike基础使用入门_Cobalt Strike联动msfconsole
随机推荐
阿里云混合云首席架构师张晓丹:政企混合云技术架构的演进和发展
Lldb common commands
查找GBase 8c数据库当前索引?
"Emergency response practice" logparser log analysis practice
DP summary of ACM in recent two weeks
Abnova peptide design and synthesis solutions
What if the ECS forgets its password? How can I retrieve my forgotten password?
Jimureport building block report - what problems does the layout design solve?
Recognize workplus again, not only im but also enterprise mobile application management expert
Collagenase -- four types of crude collagenase from Worthington
Popularization of children's programming education in specific scenarios
Powerbi - for you who are learning
Ext4 file system jam caused by MEM CGroup OOM
少儿编程课程改革后的培养方式
How to control CDN traffic gracefully in cloud development?
C语言自定义类型的介绍(结构体,枚举,联合体,位段)
Deep learning common optimizer summary
oracle数据库提示无操作权限的问题
What are the advantages of ECS? Is ECS better than VM?
Precautions for online education and training industry filing