<p>You are given a string <code>s</code>. You can convert <code>s</code> to a <span data-keyword="palindrome-string">palindrome</span> by adding characters in front of it.</p>

<p>Return <em>the shortest palindrome you can find by performing this transformation</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> s = "aacecaaa"
<strong>Output:</strong> "aaacecaaa"
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> s = "abcd"
<strong>Output:</strong> "dcbabcd"
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>0 &lt;= s.length &lt;= 5 * 10<sup>4</sup></code></li>
	<li><code>s</code> consists of lowercase English letters only.</li>
</ul>

class Solution {
private:
string reverse(string s){
    int n=s.length();
    int i=n-1;
    string ans=s;
    while(i>=0){
        ans[n-1-i]=s[i];
        i--;
    }
    return ans;
}
bool ispalindrome(string s, int left, int right){

    int mid=left+(right-left)/2;
    int i=left;
    while(i<=mid){
        if(s[i]==s[right-i+left])
        i++;
        else
        return false;
    }
    return true;
}


public:
    string shortestPalindrome(string s) {

    int len=s.length();
    if(len<=1)
    return s;

    // int i=0;
    // int index=-1;
    // while(i<len)
    // {
    //     if(ispalindrome(s, 0, i))
    //     index=i;
    //     i++;
    // }
    // index++;
    // s=reverse(s.substr(index, len))+s;

    // return s;
    int i=0;
    
    for(int j=len-1;j>=0;j--){
        if(s[j]==s[i])
        i++;
    }
    if(i==len)
    return s;
    s=reverse(s.substr(i, len))+shortestPalindrome(s.substr(0,i))+s.substr(i);
return s;
        
    }
};
10100