-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path100-is_palindrome.c
45 lines (38 loc) · 949 Bytes
/
100-is_palindrome.c
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "main.h"
/**
* _strlen_recursion - function that returns the length of a string
* @s: the string to get its length
* Return: length of the string
*/
int _strlen_recursion(char *s)
{
if (*s == '\0')
return (0);
return (1 + _strlen_recursion(s + 1));
}
/**
* check_palindrome - Checks if a string is a palindrome recursively
* @s: The string to check
* @i: The index of the first character to compare
* @len: The length of the string
* Return: 1 if the string is a palindrome, 0 otherwise
*/
int check_palindrome(char *s, int i, int len)
{
if (*(s + i) != *(s + len - 1))
return (0);
if (i >= len)
return (1);
return (check_palindrome(s, i + 1, len - 1));
}
/**
* is_palindrome - checks if a string is a palindrome
* @s: string to reverse
* Return: 1 if a string is a palindrome and 0 if not
*/
int is_palindrome(char *s)
{
if (*s == 0)
return (1);
return (check_palindrome(s, 0, _strlen_recursion(s)));
}