Easy
Given two arrays of integers a and b, obtain the array formed by the elements of a followed by the elements of b.
Example
For a = [2, 2, 1] and b = [10, 11], the output should be
concatenateArrays(a, b) = [2, 2, 1, 10, 11].
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] array.integer a
Guaranteed constraints:
1 ≤ a.length ≤ 10,
1 ≤ a[i] ≤ 15. -
[input] array.integer b
Guaranteed constraints:
0 ≤ b.length ≤ 10,
1 ≤ b[i] ≤ 15. -
[output] array.integer
[C] Syntax Tips
// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
char * answer = malloc(strlen(name) + 8);
printf("This prints to the console when you Run Tests");
strcpy(answer, "Hello, ");
strcat(answer, name);
return answer;
}
더보기
Solution
// Arrays are already defined with this interface:
// typedef struct arr_##name {
// int size;
// type *arr;
// } arr_##name;
//
// arr_##name alloc_arr_##name(int len) {
// arr_##name a = {len, len > 0 ? malloc(sizeof(type) * len) : NULL};
// return a;
// }
//
//
arr_integer concatenateArrays(arr_integer a,arr_integer b)
{
arr_integer c=alloc_arr_integer(a.size+b.size);
for(int i=0;i<c.size;i++)
c.arr[i]=i<a.size?a.arr[i]:b.arr[i-a.size];
return c;
}
728x90
'Codesignal' 카테고리의 다른 글
<Codesignal> Is Smooth? (0) | 2020.04.14 |
---|---|
<Codesignal> Remove Array Part (0) | 2020.04.14 |
<Codesignal> First Reverse Try (0) | 2020.04.14 |
<Codesignal> Create Array (0) | 2020.04.14 |
<Codesignal> Count Black Cells (0) | 2020.04.14 |