Skip to content

Commit db4efbd

Browse files
committed
🎉 #1332. Remove Palindromic Subsequences
1 parent 618550f commit db4efbd

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Diff for: #1332. Remove Palindromic Subsequences/Solution.java

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @Author: Goog Tech
3+
* @Date: 2020-08-29 17:22:24
4+
* @LastEditTime: 2020-08-29 17:22:39
5+
* @Description: https://leetcode-cn.com/problems/remove-palindromic-subsequences/
6+
* @FilePath: \leetcode-googtech\#1332. Remove Palindromic Subsequences\Solution.java
7+
* @WebSite: https://algorithm.show/
8+
*/
9+
10+
class Solution {
11+
12+
// 1.空字符串 删除 0 次
13+
// 2.回文字符窜 删除 1 次
14+
// 3.非回文字符串 删除 2 次 (一次删除全部a , 一次删除全部b)
15+
// 注: 回文子序列不是回文子字符串,比如"aababdaba",其中"aaaaa"就是它的回文子序列
16+
public int removePalindromeSub(String s) {
17+
if("".equals(s)) return 0;
18+
return s.equals(new StringBuilder(s).reverse().toString()) == true ? 1 : 2;
19+
}
20+
}

Diff for: #1332. Remove Palindromic Subsequences/Solution.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'''
2+
Author: Goog Tech
3+
Date: 2020-08-29 17:22:29
4+
LastEditTime: 2020-08-29 17:23:00
5+
Description: https://leetcode-cn.com/problems/remove-palindromic-subsequences/
6+
FilePath: \leetcode-googtech\#1332. Remove Palindromic Subsequences\Solution.py
7+
WebSite: https://algorithm.show/
8+
'''
9+
10+
class Solution(object):
11+
12+
# 1.空字符串 删除 0 次
13+
# 2.回文字符窜 删除 1 次
14+
# 3.非回文字符串 删除 2 次 (一次删除全部a , 一次删除全部b)
15+
# 注: 回文子序列不是回文子字符串,比如"aababdaba",其中"aaaaa"就是它的回文子序列
16+
def removePalindromeSub(self, s):
17+
"""
18+
:type s: str
19+
:rtype: int
20+
"""
21+
return 0 if not s else 1 if s[::-1] == s else 2

0 commit comments

Comments
 (0)