From 226bdc0ea67332e2814337f55215b160a914a13a Mon Sep 17 00:00:00 2001 From: Joshua Yoon Date: Thu, 21 Oct 2021 20:32:48 -0500 Subject: [PATCH 1/3] Completed Array1 --- DiagonalTraverse.java | 43 +++++++++++++++++++++++++++++++++++++++++++ ProductArraySelf.java | 23 +++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 DiagonalTraverse.java create mode 100644 ProductArraySelf.java diff --git a/DiagonalTraverse.java b/DiagonalTraverse.java new file mode 100644 index 00000000..ba60b2d3 --- /dev/null +++ b/DiagonalTraverse.java @@ -0,0 +1,43 @@ +public class DiagonalTraverse { + public int[] findDiagOrder(int[][] mat) { + // up = 1; + // down = 0; + if (mat == null) { + return null; + } + + int m = mat.length * mat[0].length; + int[] diagonal = new int[m]; + int direction = 1, i = 0, col = 0, row = 0; + + while (i < m) { + diagonal[i] = mat[row][col]; + i++; + // Direction = 1 + if (direction == 1) { + if (row == 0) { + col++; + direction = 0; + } else if (col == mat[0].length - 1) { + row++; + direction = 0; + } else { + col++; + row--; + } + } else { + if (col == 0) { + row++; + direction = 1; + } else if (row == mat.length - 1) { + col++; + direction = 1; + } else { + col--; + row++; + } + } + } + return diagonal; + } +} diff --git a/ProductArraySelf.java b/ProductArraySelf.java new file mode 100644 index 00000000..27404a53 --- /dev/null +++ b/ProductArraySelf.java @@ -0,0 +1,23 @@ + +class ProductArraySelf { + public int[] productArrayself(int[] nums) { + int[] product = new int[nums.length]; + + for (int i = 0; i < nums.length; i++) { + product[i] = 1; + } + for (int i = 1; i < nums.length; i++) { + product[i] = product[i - 1] * nums[i - 1]; + } + int right = 1; + + for (int i = nums.length - 1; i >= 0; i--) { + product[i] = right * product[i]; + right = nums[i]; + } + return product; + + // time: O(n) + // space: O(n) + } +} \ No newline at end of file From f98b9936dd04928595fa2ddf102003fd4bf183b5 Mon Sep 17 00:00:00 2001 From: Joshua Yoon Date: Sat, 27 Jun 2026 21:59:04 -0500 Subject: [PATCH 2/3] array-1 --- DiagonalTraverse.java | 55 +++++++++++++++++-------------------------- ProductArraySelf.java | 25 +++++++------------- 2 files changed, 31 insertions(+), 49 deletions(-) diff --git a/DiagonalTraverse.java b/DiagonalTraverse.java index ba60b2d3..9bd75eee 100644 --- a/DiagonalTraverse.java +++ b/DiagonalTraverse.java @@ -1,43 +1,32 @@ public class DiagonalTraverse { public int[] findDiagOrder(int[][] mat) { - // up = 1; - // down = 0; - if (mat == null) { - return null; - } - - int m = mat.length * mat[0].length; - int[] diagonal = new int[m]; - int direction = 1, i = 0, col = 0, row = 0; - - while (i < m) { - diagonal[i] = mat[row][col]; - i++; - // Direction = 1 - if (direction == 1) { - if (row == 0) { - col++; - direction = 0; - } else if (col == mat[0].length - 1) { - row++; - direction = 0; + int row = mat.length; + int col = mat[0].length; + int[] ans = new int[row*col]; + int r = 0; + int c = 0; + boolean flag = true; + for (int i=0; i= 0; i--) { - product[i] = right * product[i]; - right = nums[i]; + for (int j=nums.length-2; j>=0; j--){ + rProduct = rProduct * nums[j+1]; + ans[j] = rProduct * ans[j]; } - return product; - - // time: O(n) - // space: O(n) + return ans; } } \ No newline at end of file From bb2850637550872426927dc2de27af469a629ffc Mon Sep 17 00:00:00 2001 From: Joshua Yoon Date: Sat, 27 Jun 2026 22:00:36 -0500 Subject: [PATCH 3/3] commit 2 --- DiagonalTraverse.java | 1 + ProductArraySelf.java | 1 + 2 files changed, 2 insertions(+) diff --git a/DiagonalTraverse.java b/DiagonalTraverse.java index 9bd75eee..37ef19db 100644 --- a/DiagonalTraverse.java +++ b/DiagonalTraverse.java @@ -29,4 +29,5 @@ public int[] findDiagOrder(int[][] mat) { } return ans; } + } diff --git a/ProductArraySelf.java b/ProductArraySelf.java index 1935895f..55b60af9 100644 --- a/ProductArraySelf.java +++ b/ProductArraySelf.java @@ -13,4 +13,5 @@ public int[] productArrayself(int[] nums) { } return ans; } + } \ No newline at end of file