We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ab70488 commit cf460b4Copy full SHA for cf460b4
214. Shortest Palindrome
@@ -0,0 +1,25 @@
1
+class Solution {
2
+public:
3
+ string shortestPalindrome(string s) {
4
+ ios_base::sync_with_stdio(false);
5
+ cin.tie(NULL);
6
+ cout.tie(NULL);
7
+ // Note:
8
+
9
10
11
+ string originalString = s;
12
+ reverse(s.begin(), s.end());
13
14
+ int sz = s.size();
15
16
+ for(int i = 0 ; i <= sz - 1 ; i++){
17
+ if(!memcmp(originalString.c_str(), s.c_str() + i, sz - i)){
18
+ return s.substr(0, i) + originalString;
19
+ }
20
21
22
+ return s + originalString;
23
24
25
+};
0 commit comments