Skip to content

Commit

Permalink
chlng8
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriSpiridonov committed Mar 8, 2021
1 parent 1d32191 commit ace2c6a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Challenges/2021/March-LeetCoding-Challenge.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ None
|820.|[Short Encoding of Words](https://leetcode.com/problems/short-encoding-of-words/)|[Python](/Medium/820.ShortEncodingofWords.py)|Medium|
|706.|[Design HashMap](https://leetcode.com/problems/design-hashmap/)|[Python](/Easy/706.DesignHashMap.py)|Easy|

## Week 2
||Title|Solution|Difficulty|
| ----: | --- | --- | --- |
|1332.|[Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences/)|[Python](/Easy/1332.RemovePalindromicSubsequences.py)|Easy|

## License
The code is open-source and licensed under the [MIT License](/LICENSE).
56 changes: 56 additions & 0 deletions Easy/1332.RemovePalindromicSubsequences.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'''
Given a string s consisting only of letters 'a' and 'b'.
In a single step you can remove one palindromic
subsequence from s.
Return the minimum number of steps to make the given
string empty.
A string is a subsequence of a given string, if it is
generated by deleting some characters of a given string
without changing its order.
A string is called palindrome if is one that reads the
same backward as well as forward.
Example:
Input: s = "ababa"
Output: 1
Explanation: String is already palindrome
Example:
Input: s = "abb"
Output: 2
Explanation: "abb" -> "bb" -> "".
Remove palindromic subsequence "a" then "bb".
Example:
Input: s = "baabb"
Output: 2
Explanation: "baabb" -> "b" -> "".
Remove palindromic subsequence "baab" then "b".
Example:
Input: s = ""
Output: 0
Constraints:
- 0 <= s.length <= 1000
- s only consists of letters 'a' and 'b'
'''
#Difficulty: Easy
#49 / 49 test cases passed.
#Runtime: 32 ms
#Memory Usage: 14.1 MB

#Runtime: 32 ms, faster than 58.63% of Python3 online submissions for Remove Palindromic Subsequences.
#Memory Usage: 14.1 MB, less than 90.00% of Python3 online submissions for Remove Palindromic Subsequences.

class Solution:
def removePalindromeSub(self, s: str) -> int:
if not s:
return 0
elif s == s[::-1]:
return 1
else:
return 2
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Python solutions of LeetCode problems.
![Language](https://img.shields.io/badge/language-Python-blue.svg)&nbsp;
![Problems Solved](https://img.shields.io/badge/problems%20solved-517%2F1618-orange)&nbsp;
![Problems Solved](https://img.shields.io/badge/problems%20solved-518%2F1618-orange)&nbsp;
[![License](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)&nbsp;
![Update](https://img.shields.io/badge/update-Daily-brightgreen.svg)&nbsp;
<br><br>
Expand All @@ -21,7 +21,7 @@ In this repository provided my Python solutions of LeetCode problems.
2021:
- [January LeetCoding Challenge](/Challenges/2021/January-LeetCoding-Challenge.md) - 27/31
- [February LeetCoding Challenge](/Challenges/2021/February-LeetCoding-Challenge.md) - 23/28
- [March LeetCoding Challenge](/Challenges/2021/March-LeetCoding-Challenge.md) - 7/31
- [March LeetCoding Challenge](/Challenges/2021/March-LeetCoding-Challenge.md) - 8/31
<br><br>
## Solutions
*P.S. If you like this, please leave me a star.*
Expand Down Expand Up @@ -432,6 +432,7 @@ In this repository provided my Python solutions of LeetCode problems.
|1325.|[Delete Leaves With a Given Value](https://leetcode.com/problems/delete-leaves-with-a-given-value/)|[Python](/Medium/1325.DeleteLeavesWithaGivenValue.py)|Medium|`DFS`, `recursion`|
|1329.|[Sort the Matrix Diagonally](https://leetcode.com/problems/sort-the-matrix-diagonally/)|[Python](/Medium/1329.SorttheMatrixDiagonally.py)|Medium|`List`|
|1331.|[Rank Transform of an Array](https://leetcode.com/problems/rank-transform-of-an-array/)|[Python](/Easy/1331.RankTransformofanArray.py)|Easy|`Enumerate`|
|1332.|[Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences/)|[Python](/Easy/1332.RemovePalindromicSubsequences.py)|Easy|Bad problem question|
|1337.|[The K Weakest Rows in a Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix/)|[Python](/Easy/1337.TheKWeakestRowsinaMatrix.py)|Easy||
|1338.|[Reduce Array Size to The Half](https://leetcode.com/problems/reduce-array-size-to-the-half/)|[Python](/Medium/1338.ReduceArraySizetoTheHalf.py)|Medium|`Dictionary`, `Enumerate`|
|1342.|[Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/)|[Python](https://github.com/YuriSpiridonov/LeetCode/blob/master/Easy/1342.NumberofStepstoReduceaNumbertoZero.py)|Easy|`while loop`|
Expand Down

0 comments on commit ace2c6a

Please sign in to comment.