其他分享
首页 > 其他分享> > 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;  // 

标签:count,int,isConnected,vector,dfs,visited,leetcode,547
来源: https://www.cnblogs.com/ymec/p/15132940.html