aboutsummaryrefslogtreecommitdiff
path: root/most_beautiful_item_query.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 /most_beautiful_item_query.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 'most_beautiful_item_query.c')
-rw-r--r--most_beautiful_item_query.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/most_beautiful_item_query.c b/most_beautiful_item_query.c
index 42749fd..caae884 100644
--- a/most_beautiful_item_query.c
+++ b/most_beautiful_item_query.c
@@ -58,16 +58,15 @@ int main() {
q1[] = {1, 2, 3, 4, 5, 6}, rs1;
int i2i[4][2] = {{1, 2}, {1, 2}, {1, 3}, {1, 4}}, q2[] = {1}, rs2;
int i3i[1][2] = {{10, 1000}}, q3[] = {5}, rs3;
- struct two_d_arr i1, i2, i3;
- two_d_arr_init(&i1, 5, 2, i1i);
- two_d_arr_init(&i2, 4, 2, i2i);
- two_d_arr_init(&i3, 1, 2, i3i);
- int *mb1 =
- maximumBeauty(i1.arr, i1.row_size, i1.col_size, q1, ARRAY_SIZE(q1), &rs1);
- int *mb2 =
- maximumBeauty(i2.arr, i2.row_size, i2.col_size, q2, ARRAY_SIZE(q2), &rs2);
- int *mb3 =
- maximumBeauty(i3.arr, i3.row_size, i3.col_size, q3, ARRAY_SIZE(q3), &rs3);
+ struct two_d_arr *i1 = two_d_arr_init(5, 2, i1i);
+ struct two_d_arr *i2 = two_d_arr_init(4, 2, i2i);
+ struct two_d_arr *i3 = two_d_arr_init(1, 2, i3i);
+ int *mb1 = maximumBeauty(i1->arr, i1->row_size, i1->col_size, q1,
+ ARRAY_SIZE(q1), &rs1);
+ int *mb2 = maximumBeauty(i2->arr, i2->row_size, i2->col_size, q2,
+ ARRAY_SIZE(q2), &rs2);
+ int *mb3 = maximumBeauty(i3->arr, i3->row_size, i3->col_size, q3,
+ ARRAY_SIZE(q3), &rs3);
for (int i = 0; i < rs1; i++)
printf("%d ", mb1[i]); // expect: 2 4 5 5 6 6
printf("\n");
@@ -78,5 +77,7 @@ int main() {
printf("%d ", mb3[i]); // expect: 0
printf("\n");
free(mb1), free(mb2), free(mb3);
- two_d_arr_free(&i1), two_d_arr_free(&i2), two_d_arr_free(&i3);
+ two_d_arr_free(i1);
+ two_d_arr_free(i2);
+ two_d_arr_free(i3);
}