From 66cb34aa5536fc61aa4acaed66dcfae5d457629e Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Oct 2025 15:08:52 -0700 Subject: [PATCH] Done Arrays2 --- DisappearedNum.java | 21 ++++++++++++++++++ LifeGame.java | 52 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 DisappearedNum.java create mode 100644 LifeGame.java diff --git a/DisappearedNum.java b/DisappearedNum.java new file mode 100644 index 00000000..c810557f --- /dev/null +++ b/DisappearedNum.java @@ -0,0 +1,21 @@ +class Solution { + public List findDisappearedNumbers(int[] nums) { + List result = new ArrayList<>(); + HashSet set = new HashSet<>(); + int n = nums.length; + + for (int i = 0; i < n; i++) { + set.add(nums[i]); // add all the elements to has set + } + + for (int i = 1; i <= n; i++) { + if (!set.contains(i)) { //check whether set contains the nu,ber or not + result.add(i); + } + } + return result; + } +} + +Time complexity : O(n) +space complexity: O(n) \ No newline at end of file diff --git a/LifeGame.java b/LifeGame.java new file mode 100644 index 00000000..b529f568 --- /dev/null +++ b/LifeGame.java @@ -0,0 +1,52 @@ +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