当前位置:网站首页>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)边栏推荐
- Abnova membrane protein lipoprotein solution
- 少儿编程课程改革后的培养方式
- Advanced authentication of uni app [Day12]
- Chemical properties and specificity of Worthington Papain
- Doctor application | Hong Kong University of science and Technology (Guangzhou) Mr. Liu Hao recruits the full award doctor / Master in data mining
- Verifying data models in golang
- Powerbi - for you who are learning
- What does VPS server mean? What is the difference between a VPS server and an ECS?
- SAP mts/ato/mto/eto topic 10: ETO mode q+ empty mode unvalued inventory policy customization
- Web penetration test - 5. Brute force cracking vulnerability - (8) PostgreSQL password cracking
猜你喜欢

Final summary of freshman semester (supplement knowledge loopholes)

SAP mts/ato/mto/eto topic 7: ATO mode 1 m+m mode strategy 82 (6892)

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

Are you ready for the exam preparation strategy of level II cost engineer in 2022?
uni-app进阶之认证【day12】

Introduction to C language custom types (structure, enumeration, union, bit segment)

An interface testing software that supports offline document sharing in the Intranet

少儿编程教育在特定场景中的普及作用

线性回归的损失和优化,机器学习预测房价

apipost接口断言详解
随机推荐
DP summary of ACM in recent two weeks
Ribbon
How to restart the ECS? What are the differences between ECS restart and normal computers?
Weibo International Edition changed its name to Weibo light sharing Edition
SAP MTS/ATO/MTO/ETO专题之十:ETO模式 Q+空模式 未估价库存 策略自定义
Abnova peptide design and synthesis solutions
Two most practical methods for cadence OrCAD capture to batch modify network names graphic tutorial and video demonstration
Abnova膜蛋白脂蛋白体解决方案
阿里云混合云首席架构师张晓丹:政企混合云技术架构的演进和发展
How to add a domain name to ECS? What are the advantages of ECS?
Data acquisition gateway intelligent industrial Internet of things
Replication of variables in golang concurrency
mini-Web框架:装饰器方式的添加路由 | 黑马程序员
I have an agreement with IOT
Final summary of freshman semester (supplement knowledge loopholes)
Deep learning common optimizer summary
ribbon
How to select a suitable optical fiber tester
SAP MTS/ATO/MTO/ETO专题之七:ATO模式1 M+M模式策略用82(6892)
What technology is VPS? How does the server VPS?