Skip to content

Commit

Permalink
add 73 java, update progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Mar 4, 2024
1 parent db3cd51 commit c9e6252
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions data/progress.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
13 changes: 9 additions & 4 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -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)']
Expand Down
Original file line number Diff line number Diff line change
@@ -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<rows;i++){
for(int j=0;j<cols;j++){
if(matrix[i][j] == 0)
isOriginalZero[i][j] = true;
else
continue;
}
}

for(int i=0;i<rows;i++){
for(int j=0;j<cols;j++){
int currRow = i;
int currCol = j;
if(matrix[currRow][currCol]==0 && isOriginalZero[currRow][currCol]){
for(int c=0;c<currCol;c++){
matrix[currRow][c] = 0;
}
for(int c=currCol;c<cols;c++){
matrix[currRow][c] = 0;
}

for(int r=0;r<currRow;r++){
matrix[r][currCol] = 0;
}
for(int r=currRow;r<rows;r++){
matrix[r][currCol] = 0;
}
}
else
continue;
}
}
}

}

0 comments on commit c9e6252

Please sign in to comment.