-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy path100-is_palindrome.c
More file actions
44 lines (41 loc) · 814 Bytes
/
100-is_palindrome.c
File metadata and controls
44 lines (41 loc) · 814 Bytes
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
#include "main.h"
/**
* _strlen_recursion - returns the length of a string.
* @s: string
* Return: the length of a string.
*/
int _strlen_recursion(char *s)
{
if (*s == '\0')
return (0);
else
return (1 + _strlen_recursion(s + 1));
}
/**
* comparator - compares each character of the string.
* @s: string
* @n1: smallest iterator.
* @n2: biggest iterator.
* Return: .
*/
int comparator(char *s, int n1, int n2)
{
if (*(s + n1) == *(s + n2))
{
if (n1 == n2 || n1 == n2 + 1)
return (1);
return (0 + comparator(s, n1 + 1, n2 - 1));
}
return (0);
}
/**
* is_palindrome - detects if a string is a palindrome.
* @s: string.
* Return: 1 if s is a palindrome, 0 if not.
*/
int is_palindrome(char *s)
{
if (*s == '\0')
return (1);
return (comparator(s, 0, _strlen_recursion(s) - 1));
}