1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include <iostream>
using namespace std;
bool isPalindromeArray(int nums[], int len, int start) {
int end = (len - start) / 2;
for (int i = start; i < end; i++) {
if (nums[i] != nums[len - 1 - i])
return false;
}
return true;
}
int isConcatOfTwoPalindromes(int nums[], int len) {
int border = len / 2 + 1;
return isPalindromeArray(nums, border, 0) && isPalindromeArray(nums, len, border);
}
int main() {
int numbers1[9] = { 1, 2, 3, 2, 1, 4, 5, 5, 4 };
cout << isConcatOfTwoPalindromes(numbers1, 9) << endl;
int numbers2[5] = { 1, 2, 3, 4, 5 };
cout << isConcatOfTwoPalindromes(numbers2, 5) << endl;
int numbers3[5] = { 1, 2, 3, 2, 1 };
cout << isConcatOfTwoPalindromes(numbers3, 5) << endl;
}
|