Skip to content

Instantly share code, notes, and snippets.

@patelpreet422
Last active June 7, 2018 21:12
Show Gist options
  • Save patelpreet422/6d0ab4f25d2d499733c4f75f9039a2a6 to your computer and use it in GitHub Desktop.
Save patelpreet422/6d0ab4f25d2d499733c4f75f9039a2a6 to your computer and use it in GitHub Desktop.
Palindrome using recursion
#include <iostream>
#include <string>
using namespace std;
bool isPalindrome(const string &str, int low, int high)
{
if (low >= high)return true;
if (str[low] != str[high])return false;
return isPalindrome(str, ++low, --high);
}
bool isPalindrome(const string &str)
{
return isPalindrome(str, 0, str.size()-1);
}
int main()
{
cout << boolalpha << isPalindrome("boc") << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment