当前位置:   article > 正文

leetcode刷题python之长度最小的子数组_字符串数组中长度最小的元素 python

字符串数组中长度最小的元素 python

字符串操作,使用了双指针算法,但是感觉很费时间啊。。难道是我自己也有写的不好的地方?

class Solution:
    def minSubArrayLen(self, s: int, nums: List[int]) -> int:
        # if not nums: return 0
        left = 0
        right = 0
        min_len = float("inf")
        while right < len(nums):
            right += 1
            while sum(nums[left: right]) >= s:
                if right - left < min_len:
                    min_len = right - left
                left += 1
        return min_len if min_len != float("inf") else 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/993184
推荐阅读
相关标签
  

闽ICP备14008679号