diff options
author | Jack Sangdahl <[email protected]> | 2025-08-27 12:45:33 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-08-27 12:45:33 -0600 |
commit | 4552bcf5a4a356415e248dee3b201f0cea7205bb (patch) | |
tree | 9868465918c6a6841b84cd14d66923b993dd9d62 /can_make_palindrome_substr.c | |
parent | f549305fb5ca531d29dce6c2c091560f44190443 (diff) | |
download | leetcode-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 'can_make_palindrome_substr.c')
-rw-r--r-- | can_make_palindrome_substr.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/can_make_palindrome_substr.c b/can_make_palindrome_substr.c index 700c5f2..fb71a7a 100644 --- a/can_make_palindrome_substr.c +++ b/can_make_palindrome_substr.c @@ -36,11 +36,12 @@ int main() { char *s1 = "abcda", *s2 = "lyb"; int q1i[5][3] = {{3, 3, 0}, {1, 2, 0}, {0, 3, 1}, {0, 3, 2}, {0, 4, 1}}; int q2i[2][3] = {{0, 1, 0}, {2, 2, 1}}, rs1, rs2; - struct two_d_arr q1, q2; - two_d_arr_init(&q1, 5, 3, q1i); - two_d_arr_init(&q2, 2, 3, q2i); - bool *cmpq1 = canMakePaliQueries(s1, q1.arr, q1.row_size, q1.col_size, &rs1); - bool *cmpq2 = canMakePaliQueries(s2, q2.arr, q2.row_size, q2.col_size, &rs2); + struct two_d_arr *q1 = two_d_arr_init(5, 3, q1i); + struct two_d_arr *q2 = two_d_arr_init(2, 3, q2i); + bool *cmpq1 = + canMakePaliQueries(s1, q1->arr, q1->row_size, q1->col_size, &rs1); + bool *cmpq2 = + canMakePaliQueries(s2, q2->arr, q2->row_size, q2->col_size, &rs2); for (int i = 0; i < rs1; i++) printf("%d ", cmpq1[i]); // expect: 1 0 0 1 1 printf("\n"); @@ -48,5 +49,6 @@ int main() { printf("%d ", cmpq2[i]); // expect: 0 1 printf("\n"); free(cmpq1), free(cmpq2); - two_d_arr_free(&q1), two_d_arr_free(&q2); + two_d_arr_free(q1); + two_d_arr_free(q2); } |