Skip to content

Commit

Permalink
update 73 java, progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed May 20, 2024
1 parent 52775c7 commit cdd3b2e
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 7 deletions.
1 change: 1 addition & 0 deletions data/progress.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 9 additions & 6 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -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']
Expand All @@ -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']
Expand All @@ -18,26 +20,27 @@
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']
2024-06-06 -> ['226,98,253(todo)']
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']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int[]> 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
Expand Down
41 changes: 41 additions & 0 deletions leetcode_java/src/main/java/dev/workspace3.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<int[]> 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;
}

}

0 comments on commit cdd3b2e

Please sign in to comment.