当前位置:网站首页>LeetCode Algorithm 1791. Find the central node of the star chart
LeetCode Algorithm 1791. Find the central node of the star chart
2022-06-12 01:42:00 【Alex_ 12 hours a day 6 days a week】
Topic link :1791. Find the central node of the star graph
Ideas
Algorithm : Count
data structure : chart
Ideas : The central node is actually a degree of n-1 The node of , So we can use a counter to count the degrees of all nodes , If the degree is n-1, Then it is the central node . There is no given... In the input of the title n, So I went to find this by myself , And the title gives a two-dimensional array , It's not easy to operate , It is best to flatten it into a one-dimensional array , Reference article : Will be irregular Python The multidimensional array is flattened to one dimension .
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
边栏推荐
- PCA from 0 to 1
- Matlab 基础应用02 wind 股票数据介绍和使用案例:
- Common assertions for JMeter interface testing
- 一文get,最容易碰上的接口自动化测试问题汇总
- Dataset how to use dataset gracefully. After reading this article, you can fully understand the dataset in c7n/choerodon/ toothfish UI
- PHP builds a high-performance API architecture based on sw-x framework (III)
- jmeter 性能测试用 csv,这个坑有些扯蛋
- “還是學一門技術更保險!”杭州校區小哥哥轉行軟件測試,喜提10K+雙休!
- Software engineering - system flow chart
- Set up NFT blind box mall system | customized development of NFT mall software
猜你喜欢

Data in the assembly cannot start with a letter! 0 before the beginning of a letter

Jvm: thread context classloader

Program environment and pretreatment

kali安装empire过程中遇到的各种报错解决方案

Blog recommended | bookkeeper - Apache pulsar high availability / strong consistency / low latency storage implementation

Weibull Distribution韦布尔分布的深入详述(1)原理和公式

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

What is the digital twin of Yixin Huachen and what is its application value?

博文推荐|BookKeeper - Apache Pulsar 高可用 / 强一致 / 低延迟的存储实现

Jmeter接口测试之常用断言
随机推荐
Ce soir - là, j'ai battu mon collègue...
Simulated 100 questions and simulated examination for safety management personnel of metal and nonmetal mines (small open pit quarries) in 2022
【科普视频】到底什么是透镜天线?
【项目实训】校验注解
一看就懂的JMeter操作流程
Vue3+ts+node creates personal blog (database design)
螺旋矩阵(技巧)
MATLAB basic application 02 wind stock data introduction and use case:
Don't write about the full screen explosion, try the decorator mode, this is the elegant way!!
"C'est plus sûr d'apprendre une technologie!" Hangzhou Campus Little Brother transfer software test, Hi - Ti 10K + double break!
Image retrieval based on cross modal AI model
Simulated 100 questions and simulated examination for safety management personnel of metal and nonmetal mines (small open pit quarries) in 2022
Comprehensive quality of teaching resources in the second half of 2019 - subjective questions
Unity頂點動畫的陰影實現
Weekly CTF week 1: Amazing tapes
Go language learning summary (7) -- Dachang go programming specification summary
These three sentences make you not confused when you understand that you are an we media. I just do this. The monthly income of video has exceeded 10000 yuan
[从零开始学习FPGA编程-19]:快速入门篇 - 操作步骤4-1- Verilog 软件下载与开发环境的搭建- Altera Quartus II版本
Redis startup and shutdown commands
【项目实训】微信公众号模板消息推送