Comparing version 0.1.25 to 0.1.26
@@ -0,10 +1,12 @@ | ||
type MatrixValueType = string | number; | ||
declare class Matrix { | ||
private _matrix; | ||
constructor(matrix: [][]); | ||
sequence(): any[]; | ||
sequence(): MatrixValueType[]; | ||
private _dfs; | ||
dfs(): any[]; | ||
bfs(): any[]; | ||
matrix(): [][]; | ||
dfs(): MatrixValueType[]; | ||
bfs(): MatrixValueType[]; | ||
matrix(): MatrixValueType[][]; | ||
numIslands(): number; | ||
} | ||
export { Matrix }; | ||
export { Matrix, MatrixValueType }; |
@@ -76,4 +76,38 @@ "use strict"; | ||
}; | ||
Matrix.prototype.numIslands = function () { | ||
var count = 0; | ||
for (var i = 0; i < this._matrix.length; i++) { | ||
for (var j = 0; j < this._matrix[0].length; j++) { | ||
if (this._matrix[i][j] === '1') { | ||
count += 1; | ||
var queue = []; | ||
queue.push([i, j]); | ||
while (queue.length > 0) { | ||
var current = queue.shift(); | ||
if (current === undefined) { | ||
continue; | ||
} | ||
var row = current[0]; | ||
var col = current[1]; | ||
if (row < 0 || | ||
row >= this._matrix.length || | ||
col < 0 || | ||
col >= this._matrix[0].length || | ||
this._matrix[row][col] === '0') { | ||
continue; | ||
} | ||
this._matrix[row][col] = '0'; | ||
for (var i_1 = 0; i_1 < DIRECTIONS.length; i_1++) { | ||
var newRow = DIRECTIONS[i_1][0] + row; | ||
var newCol = DIRECTIONS[i_1][1] + col; | ||
queue.push([newRow, newCol]); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return count; | ||
}; | ||
return Matrix; | ||
}()); | ||
exports.Matrix = Matrix; |
{ | ||
"name": "flex-algo", | ||
"version": "0.1.25", | ||
"version": "0.1.26", | ||
"description": "\"SDK for commonly used data structure and algorithms\"", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
36693
1001