Neat DFS java solution
```\npublic class Solution {\n    public void dfs(int[][] M, int[] visited, int i) {\n        for (int j = 0; j < M.length; j++) {\n            if (M[i][j] == 1
```\npublic class Solution {\n    public void dfs(int[][] M, int[] visited, int i) {\n        for (int j = 0; j < M.length; j++) {\n            if (M[i][j] == 1 && visited[j] == 0) {\n                visited[j] = 1;\n                dfs(M, visited, j);\n            }\n        }\n    }\n    public int findCircleNum(int[][] M) {\n        int[] visited = new int[M.length];\n        int count = 0;\n        for (int i = 0; i < M.length; i++) {\n            if (visited[i] == 0) {\n                dfs(M, visited, i);\n                count++;\n            }\n        }\n        return count;\n    }\n}
[]