Number of Provinces
Problem statement
You are given an n x n matrix isConnected. If isConnected[i][j] = 1, person i and person j are direct friends.
A friend circle is a group of directly or indirectly connected people with no friendship to anyone outside the group.
Return the total number of friend circles.
Function
findCircleNum(isConnected: int[][]) → intExamples
Example 1
isConnected = [[1,1,0],[1,1,0],[0,0,1]]return = 2People 0 and 1 form one friend circle, while person 2 forms another.
Example 2
isConnected = [[1,0,0],[0,1,0],[0,0,1]]return = 3No two distinct people are friends, so every person is their own friend circle.
Example 3
isConnected = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]]return = 1The direct friendships form one transitive chain containing all four people.
Constraints
1 ≤ n ≤ 200isConnected.length = nisConnected[i].length = nisConnected[i][j]is0or1.isConnected[i][i] = 1isConnected[i][j] = isConnected[j][i]