aboutsummaryrefslogtreecommitdiff
path: root/zero_array_transformation3.c
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-08-27 12:45:33 -0600
committerJack Sangdahl <[email protected]>2025-08-27 12:45:33 -0600
commit4552bcf5a4a356415e248dee3b201f0cea7205bb (patch)
tree9868465918c6a6841b84cd14d66923b993dd9d62 /zero_array_transformation3.c
parentf549305fb5ca531d29dce6c2c091560f44190443 (diff)
downloadleetcode-4552bcf5a4a356415e248dee3b201f0cea7205bb.tar.gz
leetcode-4552bcf5a4a356415e248dee3b201f0cea7205bb.zip
chore: Refactor two_d_arr_init function
Return a pointer to a new struct, rather than initialise objects in an existing struct
Diffstat (limited to 'zero_array_transformation3.c')
-rw-r--r--zero_array_transformation3.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/zero_array_transformation3.c b/zero_array_transformation3.c
index b966099..7f323cb 100644
--- a/zero_array_transformation3.c
+++ b/zero_array_transformation3.c
@@ -115,13 +115,14 @@ int maxRemoval(int *nums, int numsSize, int **queries, int queriesSize,
int main() {
int n1[] = {2, 0, 2}, q1i[3][2] = {{0, 2}, {0, 2}, {1, 1}};
int n2[] = {1, 1, 1, 1}, q2i[4][2] = {{1, 3}, {0, 2}, {1, 3}, {1, 2}};
- struct two_d_arr q1, q2;
- two_d_arr_init(&q1, ARRAY_SIZE(q1i), ARRAY_SIZE(q1i[0]), q1i);
- two_d_arr_init(&q2, ARRAY_SIZE(q2i), ARRAY_SIZE(q2i[0]), q2i);
- printf("%d\n", maxRemoval(n1, ARRAY_SIZE(n1), q1.arr, q1.row_size,
- q1.col_size)); // expect: 1
- printf("%d\n", maxRemoval(n2, ARRAY_SIZE(n2), q2.arr, q2.row_size,
- q2.col_size)); // expect: 2
- two_d_arr_free(&q1);
- two_d_arr_free(&q2);
+ struct two_d_arr *q1 =
+ two_d_arr_init(ARRAY_SIZE(q1i), ARRAY_SIZE(q1i[0]), q1i);
+ struct two_d_arr *q2 =
+ two_d_arr_init(ARRAY_SIZE(q2i), ARRAY_SIZE(q2i[0]), q2i);
+ printf("%d\n", maxRemoval(n1, ARRAY_SIZE(n1), q1->arr, q1->row_size,
+ q1->col_size)); // expect: 2
+ printf("%d\n", maxRemoval(n2, ARRAY_SIZE(n2), q2->arr, q2->row_size,
+ q2->col_size)); // expect: 1
+ two_d_arr_free(q1);
+ two_d_arr_free(q2);
}