param { numer [ ] [ ] } M return { number } function findCircleNum ( M ) { var count = 0 ; var visited = [ ] ; for ( var i = 0 ; i < M . length ; i ++ ) { if ( visited [ i ] == undefined ) { dfs ( M , visited , i ) ; count ++ ; } } return count ; } ; param { number [ ] [ ] } M param { boolean [ ] } visited param { number } i function dfs ( M , visited , i ) { for ( var j = 0 ; j < M . length ; j ++ ) { if ( M [ i ] [ j ] == 1 && visited [ j ] == undefined ) { visited [ j ] = true ; dfs ( M , visited , j ) ; } } } export { findCircleNum } ;