156. Number of Provinces

Given an adjacency matrix isConnected for n cities. isConnected[i][j] = 1 if cities i and j are directly connected. Return the number of provinces (connected components).
Example 1
Input: isConnected = [[1,0,0],[0,1,0],[0,0,1]]
Output: 3
Explanation: Three isolated provinces.
Example 2
Input: isConnected = [[1,1,0],[1,1,0],[0,0,1]]
Output: 2
Explanation: Two provinces.
graph
JavaScript
Loading...
Line 1, Char 1