From fae01f77bbfe6ee9700b2db54b1475f44567a460 Mon Sep 17 00:00:00 2001 From: Sandarbh Singhal <123533242+Nothing-avil@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:04:33 +0530 Subject: [PATCH 01/13] feat: add solutions to lc problem: No.3032 --- .../3033.Modify the Matrix/Solution.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 solution/3000-3099/3033.Modify the Matrix/Solution.cpp diff --git a/solution/3000-3099/3033.Modify the Matrix/Solution.cpp b/solution/3000-3099/3033.Modify the Matrix/Solution.cpp new file mode 100644 index 0000000000000..263d96f45bcad --- /dev/null +++ b/solution/3000-3099/3033.Modify the Matrix/Solution.cpp @@ -0,0 +1,19 @@ +class Solution { +public: + vector> modifiedMatrix(vector>& matrix) { + int r = matrix.size(); + int c = matrix[0].size(); + for (int i = 0; i < c; i++) { + int maxs = INT_MIN; + for (int j = 0; j < r; j++) { + maxs = max(maxs, matrix[j][i]); + } + for (int j = 0; j < r; j++) { + if (matrix[j][i] == -1) { + matrix[j][i] = maxs; + } + } + } + return matrix; + } +}; From 09ec437764fc35e86b6d4db019967c4375bdd06c Mon Sep 17 00:00:00 2001 From: Sandarbh Singhal <123533242+Nothing-avil@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:05:00 +0530 Subject: [PATCH 02/13] feat: add solutions to lc problem: No.3033 From fb733559e29679a45c20de386a2dfb2f1b76ad7b Mon Sep 17 00:00:00 2001 From: Sandarbh Singhal <123533242+Nothing-avil@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:05:35 +0530 Subject: [PATCH 03/13] feat: add solutions to lc problem: No.3033 --- .../3033.Modify the Matrix/Solution.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solution/3000-3099/3033.Modify the Matrix/Solution.java diff --git a/solution/3000-3099/3033.Modify the Matrix/Solution.java b/solution/3000-3099/3033.Modify the Matrix/Solution.java new file mode 100644 index 0000000000000..4d81a09ab7fa2 --- /dev/null +++ b/solution/3000-3099/3033.Modify the Matrix/Solution.java @@ -0,0 +1,18 @@ +class Solution { + public int[][] modifiedMatrix(int[][] matrix) { + int r = matrix.length; + int c = matrix[0].length; + for (int i = 0; i < c; i++) { + int maxs = Integer.MIN_VALUE; + for (int j = 0; j < r; j++) { + maxs = Math.max(maxs, matrix[j][i]); + } + for (int j = 0; j < r; j++) { + if (matrix[j][i] == -1) { + matrix[j][i] = maxs; + } + } + } + return matrix; + } +} From a5769b85c095400530e21f3738b738e5913a61b2 Mon Sep 17 00:00:00 2001 From: Sandarbh Singhal <123533242+Nothing-avil@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:06:10 +0530 Subject: [PATCH 04/13] feat: add solutions to lc problem: No.3033 --- .../3000-3099/3033.Modify the Matrix/Solution.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 solution/3000-3099/3033.Modify the Matrix/Solution.py diff --git a/solution/3000-3099/3033.Modify the Matrix/Solution.py b/solution/3000-3099/3033.Modify the Matrix/Solution.py new file mode 100644 index 0000000000000..95f58eb4db74e --- /dev/null +++ b/solution/3000-3099/3033.Modify the Matrix/Solution.py @@ -0,0 +1,14 @@ +class Solution: + def modifiedMatrix(self, matrix: List[List[int]]) -> List[List[int]]: + rows = len(matrix) + cols = len(matrix[0]) + for i in range(cols): + max_val = float('-inf') + for j in range(rows): + max_val = max(max_val, matrix[j][i]) + + for j in range(rows): + if matrix[j][i] == -1: + matrix[j][i] = max_val + + return matrix From e1285380fc8166ee7423ee579999bad9f4630a2f Mon Sep 17 00:00:00 2001 From: Sandarbh Singhal <123533242+Nothing-avil@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:06:44 +0530 Subject: [PATCH 05/13] feat: add solutions to lc problem: No.3033 --- .../3000-3099/3033.Modify the Matrix/Solution.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 solution/3000-3099/3033.Modify the Matrix/Solution.ts diff --git a/solution/3000-3099/3033.Modify the Matrix/Solution.ts b/solution/3000-3099/3033.Modify the Matrix/Solution.ts new file mode 100644 index 0000000000000..f5f295ea6472b --- /dev/null +++ b/solution/3000-3099/3033.Modify the Matrix/Solution.ts @@ -0,0 +1,16 @@ +function modifiedMatrix(matrix: number[][]): number[][] { + const rows = matrix.length; + const cols = matrix[0].length; + for (let i = 0; i < cols; i++) { + let maxVal = Number.MIN_SAFE_INTEGER; + for (let j = 0; j < rows; j++) { + maxVal = Math.max(maxVal, matrix[j][i]); + } + for (let j = 0; j < rows; j++) { + if (matrix[j][i] === -1) { + matrix[j][i] = maxVal; + } + } + } + return matrix; +} From 5044c4df3339e85d00db70b40fbdcbd8a9e282b7 Mon Sep 17 00:00:00 2001 From: Sandarbh Singhal <123533242+Nothing-avil@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:07:56 +0530 Subject: [PATCH 06/13] feat: add solutions to lc problem: No.3033 --- .../3033.Modify the Matrix/Solution.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solution/3000-3099/3033.Modify the Matrix/Solution.go diff --git a/solution/3000-3099/3033.Modify the Matrix/Solution.go b/solution/3000-3099/3033.Modify the Matrix/Solution.go new file mode 100644 index 0000000000000..91705e9a56862 --- /dev/null +++ b/solution/3000-3099/3033.Modify the Matrix/Solution.go @@ -0,0 +1,18 @@ +func modifiedMatrix(matrix [][]int) [][]int { + r := len(matrix) + c := len(matrix[0]) + for i := 0; i < c; i++ { + maxs := math.MinInt32 + for j := 0; j < r; j++ { + if matrix[j][i] > maxs { + maxs = matrix[j][i] + } + } + for j := 0; j < r; j++ { + if matrix[j][i] == -1 { + matrix[j][i] = maxs + } + } + } + return matrix +} From 3cbe18d18025df5f0ef151811054f4e982939f9a Mon Sep 17 00:00:00 2001 From: Sandarbh Singhal <123533242+Nothing-avil@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:11:50 +0530 Subject: [PATCH 07/13] feat: add solutions to lc problem: No.3033 --- solution/3000-3099/3033.Modify the Matrix/Solution.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solution/3000-3099/3033.Modify the Matrix/Solution.go b/solution/3000-3099/3033.Modify the Matrix/Solution.go index 91705e9a56862..f366a197d8d1a 100644 --- a/solution/3000-3099/3033.Modify the Matrix/Solution.go +++ b/solution/3000-3099/3033.Modify the Matrix/Solution.go @@ -1,5 +1,5 @@ func modifiedMatrix(matrix [][]int) [][]int { - r := len(matrix) + r := len(matrix) c := len(matrix[0]) for i := 0; i < c; i++ { maxs := math.MinInt32 From 10084fda73a8922d95142365a1258c609d5c40d8 Mon Sep 17 00:00:00 2001 From: Sandarbh Singhal <123533242+Nothing-avil@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:12:20 +0530 Subject: [PATCH 08/13] feat: add solutions to lc problem: No.3033 --- .../3033.Modify the Matrix/README.md | 90 ++++++++++++++++++- 1 file changed, 87 insertions(+), 3 deletions(-) diff --git a/solution/3000-3099/3033.Modify the Matrix/README.md b/solution/3000-3099/3033.Modify the Matrix/README.md index ad26409e94e7a..2827969098941 100644 --- a/solution/3000-3099/3033.Modify the Matrix/README.md +++ b/solution/3000-3099/3033.Modify the Matrix/README.md @@ -49,19 +49,103 @@ ```python - +class Solution: + def modifiedMatrix(self, matrix: List[List[int]]) -> List[List[int]]: + rows = len(matrix) + cols = len(matrix[0]) + for i in range(cols): + max_val = float('-inf') + for j in range(rows): + max_val = max(max_val, matrix[j][i]) + + for j in range(rows): + if matrix[j][i] == -1: + matrix[j][i] = max_val + + return matrix ``` ```java - +class Solution { + public int[][] modifiedMatrix(int[][] matrix) { + int r = matrix.length; + int c = matrix[0].length; + for (int i = 0; i < c; i++) { + int maxs = Integer.MIN_VALUE; + for (int j = 0; j < r; j++) { + maxs = Math.max(maxs, matrix[j][i]); + } + for (int j = 0; j < r; j++) { + if (matrix[j][i] == -1) { + matrix[j][i] = maxs; + } + } + } + return matrix; + } +} ``` ```cpp - +class Solution { +public: + vector> modifiedMatrix(vector>& matrix) { + int r = matrix.size(); + int c = matrix[0].size(); + for (int i = 0; i < c; i++) { + int maxs = INT_MIN; + for (int j = 0; j < r; j++) { + maxs = max(maxs, matrix[j][i]); + } + for (int j = 0; j < r; j++) { + if (matrix[j][i] == -1) { + matrix[j][i] = maxs; + } + } + } + return matrix; + } +}; ``` ```go +func modifiedMatrix(matrix [][]int) [][]int { + r := len(matrix) + c := len(matrix[0]) + for i := 0; i < c; i++ { + maxs := math.MinInt32 + for j := 0; j < r; j++ { + if matrix[j][i] > maxs { + maxs = matrix[j][i] + } + } + for j := 0; j < r; j++ { + if matrix[j][i] == -1 { + matrix[j][i] = maxs + } + } + } + return matrix +} +``` +```ts +function modifiedMatrix(matrix: number[][]): number[][] { + const rows = matrix.length; + const cols = matrix[0].length; + for (let i = 0; i < cols; i++) { + let maxVal = Number.MIN_SAFE_INTEGER; + for (let j = 0; j < rows; j++) { + maxVal = Math.max(maxVal, matrix[j][i]); + } + for (let j = 0; j < rows; j++) { + if (matrix[j][i] === -1) { + matrix[j][i] = maxVal; + } + } + } + return matrix; +} ``` From 21b861b1240c23ed6754915f9ca61f638d66de58 Mon Sep 17 00:00:00 2001 From: Sandarbh Singhal <123533242+Nothing-avil@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:12:27 +0530 Subject: [PATCH 09/13] feat: add solutions to lc problem: No.3033 --- .../3033.Modify the Matrix/README_EN.md | 90 ++++++++++++++++++- 1 file changed, 87 insertions(+), 3 deletions(-) diff --git a/solution/3000-3099/3033.Modify the Matrix/README_EN.md b/solution/3000-3099/3033.Modify the Matrix/README_EN.md index 4ff7ee3bc3b14..c0049f6dae27f 100644 --- a/solution/3000-3099/3033.Modify the Matrix/README_EN.md +++ b/solution/3000-3099/3033.Modify the Matrix/README_EN.md @@ -45,19 +45,103 @@ ```python - +class Solution: + def modifiedMatrix(self, matrix: List[List[int]]) -> List[List[int]]: + rows = len(matrix) + cols = len(matrix[0]) + for i in range(cols): + max_val = float('-inf') + for j in range(rows): + max_val = max(max_val, matrix[j][i]) + + for j in range(rows): + if matrix[j][i] == -1: + matrix[j][i] = max_val + + return matrix ``` ```java - +class Solution { + public int[][] modifiedMatrix(int[][] matrix) { + int r = matrix.length; + int c = matrix[0].length; + for (int i = 0; i < c; i++) { + int maxs = Integer.MIN_VALUE; + for (int j = 0; j < r; j++) { + maxs = Math.max(maxs, matrix[j][i]); + } + for (int j = 0; j < r; j++) { + if (matrix[j][i] == -1) { + matrix[j][i] = maxs; + } + } + } + return matrix; + } +} ``` ```cpp - +class Solution { +public: + vector> modifiedMatrix(vector>& matrix) { + int r = matrix.size(); + int c = matrix[0].size(); + for (int i = 0; i < c; i++) { + int maxs = INT_MIN; + for (int j = 0; j < r; j++) { + maxs = max(maxs, matrix[j][i]); + } + for (int j = 0; j < r; j++) { + if (matrix[j][i] == -1) { + matrix[j][i] = maxs; + } + } + } + return matrix; + } +}; ``` ```go +func modifiedMatrix(matrix [][]int) [][]int { + r := len(matrix) + c := len(matrix[0]) + for i := 0; i < c; i++ { + maxs := math.MinInt32 + for j := 0; j < r; j++ { + if matrix[j][i] > maxs { + maxs = matrix[j][i] + } + } + for j := 0; j < r; j++ { + if matrix[j][i] == -1 { + matrix[j][i] = maxs + } + } + } + return matrix +} +``` +```ts +function modifiedMatrix(matrix: number[][]): number[][] { + const rows = matrix.length; + const cols = matrix[0].length; + for (let i = 0; i < cols; i++) { + let maxVal = Number.MIN_SAFE_INTEGER; + for (let j = 0; j < rows; j++) { + maxVal = Math.max(maxVal, matrix[j][i]); + } + for (let j = 0; j < rows; j++) { + if (matrix[j][i] === -1) { + matrix[j][i] = maxVal; + } + } + } + return matrix; +} ``` From 0127e38d70e2cc8a9031e5e1a3522ccd3c5bf51c Mon Sep 17 00:00:00 2001 From: Nothing-avil Date: Sun, 11 Feb 2024 07:45:33 +0000 Subject: [PATCH 10/13] style: format code and docs with prettier --- solution/3000-3099/3033.Modify the Matrix/README.md | 4 ++-- solution/3000-3099/3033.Modify the Matrix/README_EN.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/solution/3000-3099/3033.Modify the Matrix/README.md b/solution/3000-3099/3033.Modify the Matrix/README.md index 2827969098941..4b586987de54a 100644 --- a/solution/3000-3099/3033.Modify the Matrix/README.md +++ b/solution/3000-3099/3033.Modify the Matrix/README.md @@ -57,11 +57,11 @@ class Solution: max_val = float('-inf') for j in range(rows): max_val = max(max_val, matrix[j][i]) - + for j in range(rows): if matrix[j][i] == -1: matrix[j][i] = max_val - + return matrix ``` diff --git a/solution/3000-3099/3033.Modify the Matrix/README_EN.md b/solution/3000-3099/3033.Modify the Matrix/README_EN.md index c0049f6dae27f..93470f03836bf 100644 --- a/solution/3000-3099/3033.Modify the Matrix/README_EN.md +++ b/solution/3000-3099/3033.Modify the Matrix/README_EN.md @@ -53,11 +53,11 @@ class Solution: max_val = float('-inf') for j in range(rows): max_val = max(max_val, matrix[j][i]) - + for j in range(rows): if matrix[j][i] == -1: matrix[j][i] = max_val - + return matrix ``` From d5da1425289dd6ff1f0a7393867a9d9b68815502 Mon Sep 17 00:00:00 2001 From: Sandarbh Singhal <123533242+Nothing-avil@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:20:23 +0530 Subject: [PATCH 11/13] feat: add solutions to lc problem: No.3033 --- solution/3000-3099/3033.Modify the Matrix/Solution.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/solution/3000-3099/3033.Modify the Matrix/Solution.py b/solution/3000-3099/3033.Modify the Matrix/Solution.py index 95f58eb4db74e..0044d6d77e59e 100644 --- a/solution/3000-3099/3033.Modify the Matrix/Solution.py +++ b/solution/3000-3099/3033.Modify the Matrix/Solution.py @@ -6,9 +6,7 @@ def modifiedMatrix(self, matrix: List[List[int]]) -> List[List[int]]: max_val = float('-inf') for j in range(rows): max_val = max(max_val, matrix[j][i]) - for j in range(rows): if matrix[j][i] == -1: matrix[j][i] = max_val - return matrix From 46b0f0b21cb2c8ab384ae43b03b98a17c2f5af71 Mon Sep 17 00:00:00 2001 From: Sandarbh Singhal <123533242+Nothing-avil@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:20:43 +0530 Subject: [PATCH 12/13] feat: add solutions to lc problem: No.3033 --- solution/3000-3099/3033.Modify the Matrix/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/solution/3000-3099/3033.Modify the Matrix/README.md b/solution/3000-3099/3033.Modify the Matrix/README.md index 4b586987de54a..c831f178950d4 100644 --- a/solution/3000-3099/3033.Modify the Matrix/README.md +++ b/solution/3000-3099/3033.Modify the Matrix/README.md @@ -57,11 +57,9 @@ class Solution: max_val = float('-inf') for j in range(rows): max_val = max(max_val, matrix[j][i]) - for j in range(rows): if matrix[j][i] == -1: matrix[j][i] = max_val - return matrix ``` From 7a6d68be9c537a84940b29ad00e7f913889ae703 Mon Sep 17 00:00:00 2001 From: Sandarbh Singhal <123533242+Nothing-avil@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:21:01 +0530 Subject: [PATCH 13/13] feat: add solutions to lc problem: No.3033 --- solution/3000-3099/3033.Modify the Matrix/README_EN.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/solution/3000-3099/3033.Modify the Matrix/README_EN.md b/solution/3000-3099/3033.Modify the Matrix/README_EN.md index 93470f03836bf..6956f432b6778 100644 --- a/solution/3000-3099/3033.Modify the Matrix/README_EN.md +++ b/solution/3000-3099/3033.Modify the Matrix/README_EN.md @@ -53,11 +53,9 @@ class Solution: max_val = float('-inf') for j in range(rows): max_val = max(max_val, matrix[j][i]) - for j in range(rows): if matrix[j][i] == -1: matrix[j][i] = max_val - return matrix ```