diff --git a/Game of life.java b/Game of life.java new file mode 100644 index 00000000..57e03137 --- /dev/null +++ b/Game of life.java @@ -0,0 +1,48 @@ +class Solution { + int[][] dirs; + int m,n; + + public void gameOfLife(int[][] board) { + + this.dirs = new int[][]{{-1,-1}, {-1,0}, {-1, 1}, {0, -1}, {0, 1}, {1,-1}, {1,0}, {1,1}}; + + this.m = board.length; + this.n = board[0].length; + + for(int i=0; i alive; + }else if(board[i][j] == 1 && (count < 2 || count >3)){ + board[i][j] = 2; // alive -> dead; + } + } + } + + for(int i=0; i=0 && c>=0 && r