forked from Nikhil-2002/Programming_Hactoberfest25
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome.cpp
More file actions
44 lines (36 loc) · 702 Bytes
/
palindrome.cpp
File metadata and controls
44 lines (36 loc) · 702 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 <iostream>
#include <string>
#include <algorithm>
using namespace std;
// Function to check whether the string is palindrome
string isPalindrome(string S)
{
// Stores the reverse of the string S
string P = S;
// Reverse the string P
reverse(P.begin(), P.end());
if (S == P) {
return "Yes";
}
else {
return "No";
}
}
//Function to check if string is Palindrome without using extra space
string isPalind(string &s){
int l=0, r = s.size()-1;
while(l<r){
if (s[l++] != s[r--]) return "false";
}
return "true";
}
// Driver Code
int main()
{
string S;
cout<<"Enter the string: ";
cin>>S;
cout << isPalindrome(S);
cout<<isPalind(S);
return 0;
}