From ace2c6aec3ee9f8ba79ff41d5261d492aaaee5ae Mon Sep 17 00:00:00 2001 From: Yuri Spiridonov <48239309+YuriSpiridonov@users.noreply.github.com> Date: Mon, 8 Mar 2021 14:22:15 +0100 Subject: [PATCH] chlng8 --- Challenges/2021/March-LeetCoding-Challenge.md | 5 ++ Easy/1332.RemovePalindromicSubsequences.py | 56 +++++++++++++++++++ README.md | 5 +- 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 Easy/1332.RemovePalindromicSubsequences.py diff --git a/Challenges/2021/March-LeetCoding-Challenge.md b/Challenges/2021/March-LeetCoding-Challenge.md index 155c8ca..92fff18 100644 --- a/Challenges/2021/March-LeetCoding-Challenge.md +++ b/Challenges/2021/March-LeetCoding-Challenge.md @@ -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). diff --git a/Easy/1332.RemovePalindromicSubsequences.py b/Easy/1332.RemovePalindromicSubsequences.py new file mode 100644 index 0000000..15bb089 --- /dev/null +++ b/Easy/1332.RemovePalindromicSubsequences.py @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 1edcf89..dd48ac4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Python solutions of LeetCode problems. ![Language](https://img.shields.io/badge/language-Python-blue.svg)  -![Problems Solved](https://img.shields.io/badge/problems%20solved-517%2F1618-orange)  +![Problems Solved](https://img.shields.io/badge/problems%20solved-518%2F1618-orange)  [![License](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)  ![Update](https://img.shields.io/badge/update-Daily-brightgreen.svg) 

@@ -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

## Solutions *P.S. If you like this, please leave me a star.* ★ @@ -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`|