From 562611f64a8a68a1f36a05fcf74470059b30d3d8 Mon Sep 17 00:00:00 2001 From: Nikhil_sai <118588515+nikhilsaimarri@users.noreply.github.com> Date: Tue, 21 Oct 2025 22:55:45 -0500 Subject: [PATCH] Implement Game of Life algorithm --- Game of life.java | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Game of life.java 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