Learn Algorithms from LeetCode-120 (0547. Number of Provinces)
Categories: Graph/Union Find, Level: Medium
Introduction: (Basic + Advanced + Interview Edition)
Learning Algorithms from LeetCode + Interview Success Guide
(Regular price: 3591 NTD, Discounted price until 2023/06/30 23:59)
https://hiskio.com/bundles/eCP23B397?s=tc
(Regular price: 3990 NTD, Valid for a long term)
https://bit.ly/lc2022all
Please help me click on the “SHOW EMBED” below and give it 5 likes~ If you like it, you can also give me a round of applause~
(Liking doesn’t cost anything, thank you for supporting my writing~)
Question:
There are n
cities. Some of them are connected, while some are not. If city a
is connected directly with city b
, and city b
is connected directly with city c
, then city a
is connected indirectly with city c
.
A province is a group of directly or indirectly connected cities and no other cities outside of the group.
You are given an n x n
matrix isConnected
where isConnected[i][j] = 1
if the ith
city…