leetcode-dfs-547. 省份数量

 

leetcode-dfs-547. 省份数量

 

class Solution {
public:

    int findCircleNum(vector<vector<int>>& isConnected) {
        int count = 0;
        int m = isConnected.size();
        vector<bool> visited(m,false);
        for(int i = 0; i < m; i++){
            if(!visited[i]){  // 因为visiter是引用传递,下面访问过的值会改变
                dfs(isConnected,i,visited);
                count++;
            }
        }
        return count;
    }

    void dfs(vector<vector<int>>& isConnected, int i, vector<bool> &visited){
        visited[i] = true;  // 
上一篇:LeetCode394:字符串解码


下一篇:每日一题】力扣547.省份数量(并查集练习02)