当前位置:网站首页>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阿明),一起加油、一起学习进步!
边栏推荐
- 【MySQL总结】
- 自学HarmonyOS应用开发(56)- 用Service保证应用在后台持续运行
- 【C Primer Plus第九章课后编程题】
- LABVIEW详细介绍:LABVIEW是什么软件?都可以干什么?
- 05.script_setup中的私有属性
- [Microservice~Nacos] Nacos service provider and service consumer
- exness:美国GDP萎缩,日元反弹受捧
- 9 common mistakes testers fall into
- It is really strong to apply the @Transactional transaction annotation to such perfection!
- typora 透明背景图片
猜你喜欢

canvas 中如何实现物体的框选(六)
![[Microservice~Nacos] Nacos service provider and service consumer](/img/b7/47ecd6979ccfeb270261681d6130be.png)
[Microservice~Nacos] Nacos service provider and service consumer

Detailed explanation of nacos cluster configuration

postgresql日常运维技能,适合初学者

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

【Vmware NSX-V基本架构及组件安装】

Graphical LeetCode - 593. Valid Squares (Difficulty: Moderate)

【LeetCode每日一题】——872.叶子相似的树

自学HarmonyOS应用开发(53)- 获取当前位置

jar包解压后再打包为jar
随机推荐
CAPL中的键值对(hash)数据类型
【LeetCode每日一题】——230.二叉搜索树中第K小的元素
nacos的共享配置和扩展配置
2022-07-29:一共有n个人,从左到右排列,依次编号0~n-1, h[i]是第i个人的身高, v[i]是第i个人的分数, 要求从左到右选出一个子序列,在这个子序列中的人,从左到右身高是不下降的。
postgresql日常运维技能,适合初学者
Nacos micro service ~ Nacos 】 【 configuration of the center
Self-study HarmonyOS application development (56) - Use Service to ensure that the application runs continuously in the background
[MySQL series] MySQL database foundation
CMake Tutorial Tour (1)_Basic starting point
Towards Better Understanding of Self-Supervised Representations / Q-Score
「MySQL」- 基础增删改查
更换可执行文件glibc版本的某一次挣扎
泰克Tektronix示波器软件TDS1012|TDS2002|TDS2004上位机软件NS-Scope
Validation Framework-01
LABVIEW详细介绍:LABVIEW是什么软件?都可以干什么?
[VMWARE--Shared files]
百度智能云章淼:详解企业级七层负载均衡开源软件BFE
实习经历梳理
把@Transactional事务注解用到如此炉火纯青,真的强!
js中原型链的理解,原型链解决的是什么问题?