diff --git a/data/progress.txt b/data/progress.txt index 90645d2f..e7c25b4d 100644 --- a/data/progress.txt +++ b/data/progress.txt @@ -1,3 +1,4 @@ +20240520: 73 20240519: 207,79,206,213,198 20240518: 212(todo),211,338,208(again) 20240517: 347,253(todo),91(todo),217 diff --git a/data/to_review.txt b/data/to_review.txt index 49cc38e9..f90b8c97 100644 --- a/data/to_review.txt +++ b/data/to_review.txt @@ -1,3 +1,4 @@ +2024-07-14 -> ['73'] 2024-07-13 -> ['207,79,206,213,198'] 2024-07-12 -> ['212(todo),211,338,208(again)'] 2024-07-11 -> ['347,253(todo),91(todo),217'] @@ -8,6 +9,7 @@ 2024-07-06 -> ['371'] 2024-07-05 -> ['121,252'] 2024-07-04 -> ['125'] +2024-06-23 -> ['73'] 2024-06-22 -> ['207,79,206,213,198'] 2024-06-21 -> ['212(todo),211,338,208(again)'] 2024-06-20 -> ['347,253(todo),91(todo),217'] @@ -18,6 +20,7 @@ 2024-06-15 -> ['371'] 2024-06-14 -> ['121,252'] 2024-06-13 -> ['125'] +2024-06-10 -> ['73'] 2024-06-09 -> ['207,79,206,213,198'] 2024-06-08 -> ['212(todo),211,338,208(again)'] 2024-06-07 -> ['347,253(todo),91(todo),217'] @@ -25,19 +28,19 @@ 2024-06-05 -> ['104,230,102,100'] 2024-06-04 -> ['105,106'] 2024-06-03 -> ['242,235'] -2024-06-02 -> ['371'] +2024-06-02 -> ['73', '371'] 2024-06-01 -> ['207,79,206,213,198', '121,252'] 2024-05-31 -> ['212(todo),211,338,208(again)', '125'] 2024-05-30 -> ['347,253(todo),91(todo),217'] 2024-05-29 -> ['226,98,253(todo)'] -2024-05-28 -> ['104,230,102,100'] +2024-05-28 -> ['73', '104,230,102,100'] 2024-05-27 -> ['207,79,206,213,198', '105,106'] 2024-05-26 -> ['212(todo),211,338,208(again)', '242,235'] -2024-05-25 -> ['347,253(todo),91(todo),217', '371'] +2024-05-25 -> ['73', '347,253(todo),91(todo),217', '371'] 2024-05-24 -> ['207,79,206,213,198', '226,98,253(todo)', '121,252'] -2024-05-23 -> ['212(todo),211,338,208(again)', '104,230,102,100', '125'] -2024-05-22 -> ['207,79,206,213,198', '347,253(todo),91(todo),217', '105,106'] -2024-05-21 -> ['207,79,206,213,198', '212(todo),211,338,208(again)', '226,98,253(todo)', '242,235'] +2024-05-23 -> ['73', '212(todo),211,338,208(again)', '104,230,102,100', '125'] +2024-05-22 -> ['73', '207,79,206,213,198', '347,253(todo),91(todo),217', '105,106'] +2024-05-21 -> ['73', '207,79,206,213,198', '212(todo),211,338,208(again)', '226,98,253(todo)', '242,235'] 2024-05-20 -> ['207,79,206,213,198', '212(todo),211,338,208(again)', '347,253(todo),91(todo),217', '104,230,102,100', '371'] 2024-05-19 -> ['212(todo),211,338,208(again)', '347,253(todo),91(todo),217', '226,98,253(todo)', '105,106', '121,252'] 2024-05-18 -> ['347,253(todo),91(todo),217', '226,98,253(todo)', '104,230,102,100', '242,235', '125'] diff --git a/leetcode_java/src/main/java/LeetCodeJava/Array/SetMatrixZeroes.java b/leetcode_java/src/main/java/LeetCodeJava/Array/SetMatrixZeroes.java index 0f325451..22d07e86 100644 --- a/leetcode_java/src/main/java/LeetCodeJava/Array/SetMatrixZeroes.java +++ b/leetcode_java/src/main/java/LeetCodeJava/Array/SetMatrixZeroes.java @@ -2,14 +2,52 @@ // https://leetcode.com/problems/set-matrix-zeroes/description/ +import java.util.ArrayList; +import java.util.List; + public class SetMatrixZeroes { // V0 // IDEA : ARRAY OP - // TODO: implement below // https://github.com/yennanliu/CS_basics/blob/master/leetcode_python/Array/set-matrix-zeroes.py public void setZeroes(int[][] matrix) { + if (matrix.length == 0 && matrix[0].length == 0){ + return; + } + + int l = matrix.length; + int w = matrix[0].length; + + // get zero + List collected = new ArrayList<>(); + for (int i = 0; i < w; i++){ + for (int j = 0; j < l; j++){ + if(matrix[j][i] == 0){ + collected.add(new int[]{i, j}); + } + } + } + + //System.out.println("collected = " + collected); + for (int[] point : collected){ + + //System.out.println("x = " + point[0] + " y = " + point[1]); + int x = point[0]; + int y = point[1]; + + // make x - direction as zero + for (int i = 0; i < w; i++){ + matrix[y][i] = 0; + } + + // make y - direction as zero + for (int j = 0; j < l; j++){ + matrix[j][x] = 0; + } + } + + return; } // V1 diff --git a/leetcode_java/src/main/java/dev/workspace3.java b/leetcode_java/src/main/java/dev/workspace3.java index 92f84041..e3238724 100644 --- a/leetcode_java/src/main/java/dev/workspace3.java +++ b/leetcode_java/src/main/java/dev/workspace3.java @@ -1085,4 +1085,45 @@ public int rob_2(int[] nums) { return dp[nums.length-1]; } + // LC 73 + public void setZeroes(int[][] matrix) { + + if (matrix.length == 0 && matrix[0].length == 0){ + return; + } + + int l = matrix.length; + int w = matrix[0].length; + + // get zero + List collected = new ArrayList<>(); + for (int i = 0; i < w; i++){ + for (int j = 0; j < l; j++){ + if(matrix[j][i] == 0){ + collected.add(new int[]{i, j}); + } + } + } + + //System.out.println("collected = " + collected); + for (int[] point : collected){ + + System.out.println("x = " + point[0] + " y = " + point[1]); + int x = point[0]; + int y = point[1]; + + // make x - direction as zero + for (int i = 0; i < w; i++){ + matrix[y][i] = 0; + } + + // make y - direction as zero + for (int j = 0; j < l; j++){ + matrix[j][x] = 0; + } + } + + return; + } + }