Skip to content

Commit e4421bf

Browse files
committed
update
1 parent f5aba88 commit e4421bf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* AC:Runtime: 4 ms, faster than 20.49% of C++ online submissions for Remove Palindromic Subsequences.
3+
* Memory Usage: 6.2 MB, less than 100.00% of C++ online submissions for Remove Palindromic Subsequences.
4+
*
5+
* 思路:这里是 subsequence,是子序列,而不是 substring (子字符串)。子序列不要求连续。
6+
* 所以只有两种可能,一种本身就是回文字符串,那么返回 2(空字符串返0),一种就是不回文,那么
7+
* 第一步去掉所有 ‘a’(子序列1),第二部去掉所有 'b' (子序列2),就完成了。
8+
* T:O(n) S:O(0)
9+
*/
10+
class Solution {
11+
public:
12+
int removePalindromeSub(string s) {
13+
if (s.length() == 0) {
14+
return 0;
15+
}
16+
for (int i = 0; i < s.length(); i++) {
17+
if (s[i] != s[s.length() - 1 - i]) {
18+
return 2;
19+
}
20+
}
21+
22+
return 1;
23+
}
24+
};

0 commit comments

Comments
 (0)