aboutsummaryrefslogtreecommitdiff
path: root/zero_array_transformation1.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_transformation1.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_transformation1.c')
-rw-r--r--zero_array_transformation1.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/zero_array_transformation1.c b/zero_array_transformation1.c
index 45f388c..089c0ff 100644
--- a/zero_array_transformation1.c
+++ b/zero_array_transformation1.c
@@ -33,13 +33,14 @@ bool isZeroArray(int *nums, int numsSize, int **queries, int queriesSize,
int main() {
int n1[] = {1, 0, 1}, q1i[1][2] = {{0, 2}};
int n2[] = {4, 3, 2, 1}, q2i[2][2] = {{1, 3}, {0, 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", isZeroArray(n1, ARRAY_SIZE(n1), q1.arr, q1.row_size,
- q1.col_size)); // expect: 1
- printf("%d\n", isZeroArray(n2, ARRAY_SIZE(n2), q2.arr, q2.row_size,
- q2.col_size)); // expect: 0
- 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", isZeroArray(n1, ARRAY_SIZE(n1), q1->arr, q1->row_size,
+ q1->col_size)); // expect: 1
+ printf("%d\n", isZeroArray(n2, ARRAY_SIZE(n2), q2->arr, q2->row_size,
+ q2->col_size)); // expect: 0
+ two_d_arr_free(q1);
+ two_d_arr_free(q2);
}