Leetcode 214 Solution
This article provides solution to leetcode question 214 (shortest-palindrome)
Access this page by simply typing in "lcs 214" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/shortest-palindrome
Solution
class Solution {
public:
string shortestPalindrome(string s) {
string t = s;
reverse(t.begin(), t.end());
int n = s.size();
int i = n;
for (i = n; i >= 0; i--)
{
if (s.substr(0, i) == t.substr(n - i))
break;
}
return t.substr(0, n - i) + s;
}
};