Java Solution | 100% faster | Connected Components
A must watch video if you\'re not already familier with connected compoents in graph theory: \nhttps://www.youtube.com/watch?v=z49Ohr5Ypnw\n\nclass Solution {\n
A must watch video if you\'re not already familier with connected compoents in graph theory: \nhttps://www.youtube.com/watch?v=z49Ohr5Ypnw\n```\nclass Solution {\n    public int findCircleNum(int[][] M) {\n        int N = M.length;\n        boolean[]visited = new boolean[N];\n        int count = 0;\n        \n        for(int i = 0; i < N ;i++){\n            if(!visited[i]){\n                count++;\n                dfs(M,i,visited);\n            }\n        }\n      return count;  \n    }\n    \n    \n    private void dfs(int[][]M,int i,boolean[]visited){\n        for(int j = 0 ; j < M[i].length ; j++){\n            if(!visited[j] && M[i][j] != 0){\n                visited[j] = true;\n                dfs(M,j,visited);\n            }\n        }\n    }\n    \n}\n```
['Depth-First Search', 'Java']