- #include
#include
using namespace std;
string ShortestPalindrome(string str)
{
string t = str;
reverse(t.begin(), t.end());
int n = t.size(),i=0;
for (i = n; i >= 0; i–)
{
if (str.substr(0, i) == t.substr(n-i))
{
break;
}
}
return t.substr(0,n-i)+str;
}
int main()
{
cout << ShortestPalindrome(“1233”) << endl;
system(“pause”);
return 0;
}
[LeetCode] 214. Shortest Palindrome 最短回文串
最新推荐文章于 2020-05-29 11:07:45 发布