LeetCode每日一题:双指针

2022-12-27  本文已影响0人  ShowMeCoding

1750. 删除字符串两端相同字符后的最短长度

输入:s = "cabaabac"
输出:0
解释:最优操作序列为:

class Solution:
    def minimumLength(self, s: str) -> int:
        left, right = 0, len(s) - 1
        while left < right and s[left] == s[right]:
            c = s[left]
            while left <= right and s[left] == c:
                left += 1
            while right >= left and s[right] == c:
                right -= 1
        return right - left + 1

笔记:使用双指针进行统计计数

上一篇下一篇

猜你喜欢

热点阅读