IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    2020 第36周 LeetCode 记录

    Yiran\'s Blog发表于 2020-09-06 15:04:19
    love 0
    1566. Detect Pattern of Length M Repeated K or More Times 链接到标题 判断数组中是否存在连续长度为 m 且重复次数为 k 的字符串,直接对 arr 进行切片判断。 class Solution: def containsPattern(self, arr: List[int], m: int, k: int) -> bool: i = 0 while i < len(arr): p = arr[i:i+m] if p * k == arr[i:i+m*k]: return True i += 1 return False 1567. Maximum Length of Subarray With Positive Product 链接到标题 给你一个整数数组 nums ,请你求出乘积为正数的最长子数组的长度。使用数组记录数值为负数的索引值,当数字为 0 时则重置数组,当负数数量为偶数时,则更新最大值,最大值为当前索引减去第一个非 0 数字索引,如果负数数量为奇数时,则最大值为当前索引减去第一个负数索引。


沪ICP备19023445号-2号
友情链接