Skip to content

Commit ba09adb

Browse files
authored
Create valid-palindrome-iv.cpp
1 parent 5e496d0 commit ba09adb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

C++/valid-palindrome-iv.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
// string, two pointers
5+
class Solution {
6+
public:
7+
bool makePalindrome(string s) {
8+
for (int left = 0, right = size(s) - 1, cnt = 0; left < right; ++left, --right) {
9+
if (s[left] != s[right] && ++cnt > 2) {
10+
return false;
11+
}
12+
}
13+
return true;
14+
}
15+
};

0 commit comments

Comments
 (0)