96. Number of Provinces (Adjacency Matrix)
MediumGraphs
isConnected is an n × n matrix where isConnected[i][j] = 1 means cities i and j are directly linked (the matrix is symmetric and the diagonal is 1). A province is a group of cities linked directly or indirectly. Return the number of provinces.
Example 1
Input: isConnected = [[1,1,0],[1,1,0],[0,0,1]] Output: 2
Constraints
1 ≤ n ≤ 200