当前位置:网站首页>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)边栏推荐
- The official overclocking tool of Intel XTU supports win11 22h2 and 13th generation core Raptor Lake processors
- Oracle database prompts no operation permission
- Problem: SQL create stored procedure
- mysql中表的命名
- How to add a domain name to ECS? What are the advantages of ECS?
- 查找GBase 8c数据库当前索引?
- How to build a website for ECS is the price of ECS very expensive
- 集成阿里云短信服务以及报签名不合法的原因
- What are the differences between ECs and virtual hosts? Which is better, ECS or VM?
- Lldb common commands
猜你喜欢

Let children learn the application essence of steam Education

Facebook internal announcement: instant messaging will be re integrated

什么是数据中台

少儿编程课程改革后的培养方式

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

Recognize workplus again, not only im but also enterprise mobile application management expert
Summary of Android interview questions in 2020 (intermediate)

阿里云新一代云计算体系架构 CIPU 到底是啥?

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

Abnova多肽设计和合成解决方案
随机推荐
SAP MTS/ATO/MTO/ETO专题之十:ETO模式 Q+空模式 未估价库存 策略自定义
Bi-sql distinct
Web penetration test - 5. Brute force cracking vulnerability - (8) PostgreSQL password cracking
uni-app进阶之认证【day12】
一款支持内网脱机分享文档的接口测试软件
阿里云新一代云计算体系架构 CIPU 到底是啥?
MySQL - SQL execution process
提pr,push 的时候网络超时配置方法
梯度下降法介紹-黑馬程序員機器學習講義
What technology is VPS? How does the server VPS?
What is the role of ECS? How does FTP connect to ECS configuration?
外网访问svn服务器(外网访问部署在云上的svn服务器)
阿里云混合云首席架构师张晓丹:政企混合云技术架构的演进和发展
Facebook内部通告:将重新整合即时通讯功能
ribbon
Summary of Android interview questions in 2020 (elementary)
胶原蛋白酶——Worthington四种类型的粗胶原酶
Jimureport building block report - expression introduction
C语言自定义类型的介绍(结构体,枚举,联合体,位段)
I have an agreement with IOT