-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPalindrome_String.cpp
More file actions
64 lines (51 loc) · 880 Bytes
/
Palindrome_String.cpp
File metadata and controls
64 lines (51 loc) · 880 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
https://practice.geeksforgeeks.org/problems/palindrome-string0817/1
Input: S = "abba"
Output: 1
Explanation: S is a palindrome
Example 2:
Input: S = "abc"
Output: 0
Explanation: S is not a palindrome
*/
int isPalindrome(string s)
{
// Your code goes here
int n=s.length();
int f=0;
for(int i=0;i<n/2;i++)
{
if(s[i]!=s[n-i-1])
{
f=1;
}
}
if(f==1)
{
return 0;
}else
return 1;
}
//**************************************** Using Recursion********************
#include <iostream>
using namespace std;
bool f(int i,int n,string &s)
{
if(i>=n/2)
{
return true;
}
if(s[i]!=s[s.size()-i-1])
{
return false;
}
return f(i+1,n,s);
}
int main()
{
string s="ababa";
int n=5;
int i=0;
cout<<f(i,n,s);
return 0;
}