当前位置:网站首页>LeetCode 2348. Number of all-zero subarrays
LeetCode 2348. Number of all-zero subarrays
2022-07-30 01:28:00 【Michael Armin】
1. 题目
给你一个整数数组 nums ,返回全部为 0 的 子数组 数目.
子数组 是一个数组中一段连续非空元素组成的序列.
示例 1:
输入:nums = [1,3,0,0,2,0,0,4]
输出:6
解释:
子数组 [0] 出现了 4 次.
子数组 [0,0] 出现了 2 次.
不存在长度大于 2 的全 0 子数组,所以我们返回 6 .
示例 2:
输入:nums = [0,0,0,2,0,0]
输出:9
解释:
子数组 [0] 出现了 5 次.
子数组 [0,0] 出现了 3 次.
子数组 [0,0,0] 出现了 1 次.
不存在长度大于 3 的全 0 子数组,所以我们返回 9 .
示例 3:
输入:nums = [2,10,2019]
输出:0
解释:没有全 0 子数组,所以我们返回 0 .
提示:
1 <= nums.length <= 10^5
-10^9 <= nums[i] <= 10^9
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/number-of-zero-filled-subarrays
著作权归领扣网络所有.商业转载请联系官方授权,非商业转载请注明出处.
2. 解题
- Statistically continuous 0 的个数 n,每次以当前 0 is an array of right endpoints 有 n 个
class Solution:
def zeroFilledSubarray(self, nums: List[int]) -> int:
ct = 0
c = 0
for x in nums:
if x == 0:
c += 1
ct += c
else:
c = 0
return ct
104 ms 22.9 MB Python3
我的CSDN博客地址 https://michael.blog.csdn.net/
长按或扫码关注我的公众号(Michael阿明),一起加油、一起学习进步!
边栏推荐
- [QNX Hypervisor 2.2用户手册]9.12 预留
- 自学HarmonyOS应用开发(56)- 用Service保证应用在后台持续运行
- exness:美国GDP萎缩,日元反弹受捧
- 图解LeetCode——593. 有效的正方形(难度:中等)
- 软考 --- 数据库(5)数据库控制
- 05.script_setup中的私有属性
- 2022-07-29:一共有n个人,从左到右排列,依次编号0~n-1, h[i]是第i个人的身高, v[i]是第i个人的分数, 要求从左到右选出一个子序列,在这个子序列中的人,从左到右身高是不下降的。
- 验证框架-01
- LeetCode/Scala - without the firstborn of the string of characters, the longest text string back
- 视觉系统设计实例halcon-winform-11.菜单折叠与展示
猜你喜欢

Navicat如何连接MySQL

Push the image to the Alibaba Cloud private warehouse

Navicat for mysql破解版安装

exness:美国GDP萎缩,日元反弹受捧

图解LeetCode——593. 有效的正方形(难度:中等)

【微服务~Nacos】Nacos之配置中心

Detailed introduction of @RequestParam annotation

Huawei's "genius boy" Zhihui Jun has made a new work, creating a "customized" smart keyboard from scratch

Fabric Private Data Case

nacos的共享配置和扩展配置
随机推荐
nacos集群配置详解
把@Transactional事务注解用到如此炉火纯青,真的强!
什么专业越老越吃香?
msyql set names 字符转换处理
npm ERR! code ENOTSUP npm ERR! notsup Unsupported engine for [email protected]: wanted: {“n
js中原型链的理解,原型链解决的是什么问题?
Fabric 私有数据案例
记笔记!电源自动测试系统测试电源纹波详细方法
@RequestParam注解的详细介绍
Baidu Intelligent Cloud Zhangmiao: Detailed explanation of enterprise-level seven-layer load balancing open source software BFE
Running a Fabric Application
Nacos配置中心用法详细介绍
【Flutter】混合开发之Flutter预加载解决第一次加载页面缓慢问题
[Microservice~Nacos] Configuration Center of Nacos
【微服务~Nacos】Nacos服务提供者和服务消费者
华为“天才少年”稚晖君又出新作,从零开始造“客制化”智能键盘
神经网络迭代次数的一个近似关系
Nacos micro service ~ Nacos 】 【 configuration of the center
[Flutter] Detailed explanation of the use of the Flutter inspector tool, viewing the Flutter layout, widget tree, debugging interface, etc.
diff和key的作用