From c9e62524374d0825eb3cacfc693025dcf5d34ce0 Mon Sep 17 00:00:00 2001 From: yennanliu Date: Mon, 4 Mar 2024 08:55:34 +0800 Subject: [PATCH] add 73 java, update progress --- README.md | 2 +- data/progress.txt | 1 + data/to_review.txt | 13 ++- .../LeetCodeJava/Array/SetMatrixZeroes.java | 87 +++++++++++++++++++ 4 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 leetcode_java/src/main/java/LeetCodeJava/Array/SetMatrixZeroes.java diff --git a/README.md b/README.md index 3e88fa94..f04bd3dd 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ 057 | [Insert Interval](https://leetcode.com/problems/insert-interval/) | [Python](./leetcode_python/Array/insert-interval.py) | | | Medium | Curated Top 75, good basic, `056 Merge Intervals`| AGAIN********** (4) (MUST!) 059 | [Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii/) | [Python](./leetcode_python/Array/spiral-matrix-ii.py) | _O(n^2)_ | _O(1)_ | Medium |check `# 054 Spiral Matrix`, `amazon`| AGAIN** (2) 066 | [Plus One](https://leetcode.com/problems/plus-one/) | [Python](./leetcode_python/Array/plus-one.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Array/PlusOne.java)| _O(n)_ | _O(1)_ | Easy |`basic`, `digit`, `google`| AGAIN** (3) -073 | [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) | [Python](./leetcode_python/Array/set-matrix-zeroes.py) | _O(m * n)_ | _O(1)_ | Medium |Curated Top 75, `matrix`, `amazon`| OK* (4) +073 | [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) | [Python](./leetcode_python/Array/set-matrix-zeroes.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Array/SetMatrixZeroes.java) | _O(m * n)_ | _O(1)_ | Medium |Curated Top 75, `matrix`, `amazon`| OK* (4) 080 | [Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/)| [Python](./leetcode_python/Array/remove-duplicates-from-sorted-array-ii.py) | _O(n)_ | _O(1)_ | Medium |`two pointers`,AGAIN, `basic`, `trick`, `fb`, `#26 Remove Duplicates from Sorted Array`| AGAIN************ (8) 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/)| [Python](./leetcode_python/Array/pascals-triangle.py) | _O(n^2)_ | _O(1)_ | Easy |`trick`, `basic`| AGAIN** (2) 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii/)| [Python](./leetcode_python/Array/pascals-triangle-ii.py) | _O(n^2)_ | _O(1)_ | Easy |array, check with `# 118 Pascal's Triangle`, `amazon`| OK** (4) diff --git a/data/progress.txt b/data/progress.txt index 9fe11586..9db3cb35 100644 --- a/data/progress.txt +++ b/data/progress.txt @@ -1,3 +1,4 @@ +20240304: 73 20240303: 55(again),56,62,70 20240229: 39,48(again),49,53,54 20240228: 20,21,23,33(again) diff --git a/data/to_review.txt b/data/to_review.txt index 285ca26a..d8db8739 100644 --- a/data/to_review.txt +++ b/data/to_review.txt @@ -1,23 +1,28 @@ +2024-04-28 -> ['73'] 2024-04-27 -> ['55(again),56,62,70'] 2024-04-24 -> ['39,48(again),49,53,54'] 2024-04-23 -> ['20,21,23,33(again)'] 2024-04-22 -> ['1,3,5,4,19'] +2024-04-07 -> ['73'] 2024-04-06 -> ['55(again),56,62,70'] 2024-04-03 -> ['39,48(again),49,53,54'] 2024-04-02 -> ['20,21,23,33(again)'] 2024-04-01 -> ['1,3,5,4,19'] +2024-03-25 -> ['73'] 2024-03-24 -> ['55(again),56,62,70'] 2024-03-21 -> ['39,48(again),49,53,54'] 2024-03-20 -> ['20,21,23,33(again)'] 2024-03-19 -> ['1,3,5,4,19'] +2024-03-17 -> ['73'] 2024-03-16 -> ['55(again),56,62,70'] 2024-03-13 -> ['39,48(again),49,53,54'] -2024-03-12 -> ['20,21,23,33(again)'] +2024-03-12 -> ['73', '20,21,23,33(again)'] 2024-03-11 -> ['55(again),56,62,70', '1,3,5,4,19'] +2024-03-09 -> ['73'] 2024-03-08 -> ['55(again),56,62,70', '39,48(again),49,53,54'] -2024-03-07 -> ['20,21,23,33(again)'] -2024-03-06 -> ['55(again),56,62,70', '1,3,5,4,19'] -2024-03-05 -> ['55(again),56,62,70', '39,48(again),49,53,54'] +2024-03-07 -> ['73', '20,21,23,33(again)'] +2024-03-06 -> ['73', '55(again),56,62,70', '1,3,5,4,19'] +2024-03-05 -> ['73', '55(again),56,62,70', '39,48(again),49,53,54'] 2024-03-04 -> ['55(again),56,62,70', '20,21,23,33(again)'] 2024-03-03 -> ['39,48(again),49,53,54', '1,3,5,4,19'] 2024-03-02 -> ['39,48(again),49,53,54', '20,21,23,33(again)'] diff --git a/leetcode_java/src/main/java/LeetCodeJava/Array/SetMatrixZeroes.java b/leetcode_java/src/main/java/LeetCodeJava/Array/SetMatrixZeroes.java new file mode 100644 index 00000000..0f325451 --- /dev/null +++ b/leetcode_java/src/main/java/LeetCodeJava/Array/SetMatrixZeroes.java @@ -0,0 +1,87 @@ +package LeetCodeJava.Array; + +// https://leetcode.com/problems/set-matrix-zeroes/description/ + +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) { + + } + + // V1 + public void setZeroes_1(int[][] matrix) { + boolean fr = false,fc = false; + for(int i = 0; i < matrix.length; i++) { + for(int j = 0; j < matrix[0].length; j++) { + if(matrix[i][j] == 0) { + if(i == 0) fr = true; + if(j == 0) fc = true; + matrix[0][j] = 0; + matrix[i][0] = 0; + } + } + } + for(int i = 1; i < matrix.length; i++) { + for(int j = 1; j < matrix[0].length; j++) { + if(matrix[i][0] == 0 || matrix[0][j] == 0) { + matrix[i][j] = 0; + }} + } + if(fr) { + for(int j = 0; j < matrix[0].length; j++) { + matrix[0][j] = 0; + } + } + if(fc) { + for(int i = 0; i < matrix.length; i++) { + matrix[i][0] = 0; + } + } + } + + // V2 + // https://leetcode.com/problems/set-matrix-zeroes/solutions/4800467/using-2-d-boolean-array/ + public void setZeroes_2(int[][] matrix) { + int rows = matrix.length; + int cols = matrix[0].length; + boolean[][] isOriginalZero = new boolean[rows][cols]; + + for(int i=0;i