more tests
This commit is contained in:
@@ -18,27 +18,26 @@ char* longestPalindrome(char * input_str) {
|
||||
|
||||
size_t c_start = 0;
|
||||
size_t c_end = 0;
|
||||
bool is_first = true;
|
||||
|
||||
while (start < len) {
|
||||
bool is_palindrome = false;
|
||||
end = start;
|
||||
DEBUG_LOG("start: %llu\n", start);
|
||||
DEBUG_LOG("start: %lu\n", start);
|
||||
for (size_t i = start; i < len; ++i) {
|
||||
const size_t dist = end - start + 1;
|
||||
is_palindrome = false;
|
||||
DEBUG_LOG(" dist: %llu:\n", dist);
|
||||
DEBUG_LOG(" dist: %lu:\n", dist);
|
||||
for (size_t j = 0; j < dist; ++j) {
|
||||
const size_t start_it = start + j;
|
||||
const size_t end_it = end - j;
|
||||
DEBUG_LOG(" [%llu]%c = [%llu]%c: %s\n",start_it, input_str[start_it], end_it, input_str[end_it], input_str[start_it] == input_str[end_it] ? "true" : "false");
|
||||
DEBUG_LOG(" [%lu]%c = [%lu]%c: %s\n",start_it, input_str[start_it], end_it, input_str[end_it], input_str[start_it] == input_str[end_it] ? "true" : "false");
|
||||
if (input_str[start_it] == input_str[end_it]) {
|
||||
is_palindrome = true;
|
||||
} else {
|
||||
is_palindrome = false;
|
||||
}
|
||||
}
|
||||
if (is_palindrome && end - start > c_end - c_start) break;
|
||||
if (is_palindrome) break;
|
||||
++end;
|
||||
}
|
||||
DEBUG_LOG("extracted: ");
|
||||
@@ -46,19 +45,18 @@ char* longestPalindrome(char * input_str) {
|
||||
DEBUG_LOG("%c", input_str[start + i]);
|
||||
}
|
||||
DEBUG_LOG("\n");
|
||||
DEBUG_LOG("[%llu] -> [%llu], c: [%llu] -> [%llu]\n", start, end, c_start, c_end);
|
||||
DEBUG_LOG("[%lu] -> [%lu], c: [%lu] -> [%lu]\n", start, end, c_start, c_end);
|
||||
DEBUG_LOG("\n");
|
||||
if (is_palindrome && (end - start > c_end - c_start || is_first)) {
|
||||
is_first = false;
|
||||
if (is_palindrome && end - start > c_end - c_start) {
|
||||
c_start = start;
|
||||
c_end = end;
|
||||
DEBUG_LOG("candidate: %llu -> %llu\n", c_start, c_end);
|
||||
DEBUG_LOG("candidate: %lu -> %lu\n", c_start, c_end);
|
||||
}
|
||||
++start;
|
||||
}
|
||||
|
||||
DEBUG_LOG("wow\n");
|
||||
DEBUG_LOG("[%llu] -> [%llu]: size %llu\n", c_start, c_end, c_end - c_start + 1);
|
||||
DEBUG_LOG("[%lu] -> [%lu]: size %lu\n", c_start, c_end, c_end - c_start + 1);
|
||||
char* str = (char*)malloc((c_end - c_start + 2) * sizeof(char));
|
||||
memcpy(str, input_str + start, (c_end - c_start + 1) * sizeof(char));
|
||||
str[c_end - c_start + 1] = '\0';
|
||||
|
||||
Reference in New Issue
Block a user