当前位置:网站首页>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阿明),一起加油、一起学习进步!
边栏推荐
- Replace the executable file glibc version of the one
- LeetCode/Scala - without the firstborn of the string of characters, the longest text string back
- 基于SSM实现个性化健康饮食推荐系统
- mysql 报错 is too long for user name (should be no longer than 16)
- 帽式滑环的工作原理
- 经济衰退时期的对比:如今更像历史上的哪段时期?
- Interviews with big factories under the trend of layoffs: "ByteDance"
- [Microservice~Nacos] Nacos service provider and service consumer
- 2022-07-29:一共有n个人,从左到右排列,依次编号0~n-1, h[i]是第i个人的身高, v[i]是第i个人的分数, 要求从左到右选出一个子序列,在这个子序列中的人,从左到右身高是不下降的。
- [MySQL series] MySQL database foundation
猜你喜欢
[email protected](using passwordYES)"/>Navicat报错:1045-Access denied for user [email protected](using passwordYES)

泰克Tektronix示波器软件TDS420|TDS430|TDS460上位机软件NS-Scope

Self-study HarmonyOS application development (56) - Use Service to ensure that the application runs continuously in the background

Running a Fabric Application
![[Flutter] Detailed explanation of the use of the Flutter inspector tool, viewing the Flutter layout, widget tree, debugging interface, etc.](/img/29/a6ec7e00df289f68dcd39fe4f35fd3.png)
[Flutter] Detailed explanation of the use of the Flutter inspector tool, viewing the Flutter layout, widget tree, debugging interface, etc.
![[MySQL series] MySQL database foundation](/img/50/cc75b2cdf6e52714c1d492fa1ae2c4.png)
[MySQL series] MySQL database foundation
![[VMWARE--Shared files]](/img/34/1f1609edc82c0a134886f9bf936f7f.png)
[VMWARE--Shared files]

Running a Fabric Application
![2022-07-29:一共有n个人,从左到右排列,依次编号0~n-1, h[i]是第i个人的身高, v[i]是第i个人的分数, 要求从左到右选出一个子序列,在这个子序列中的人,从左到右身高是不下降的。](/img/a0/998fb7edca5ebe5d9b1d1e8b705faa.png)
2022-07-29:一共有n个人,从左到右排列,依次编号0~n-1, h[i]是第i个人的身高, v[i]是第i个人的分数, 要求从左到右选出一个子序列,在这个子序列中的人,从左到右身高是不下降的。

The solution to the bug, the test will no longer be blamed
随机推荐
The solution to the bug, the test will no longer be blamed
裁员趋势下的大厂面试:“字节跳动”
Fabric Private Data Case
[Flutter] Flutter preloading of mixed development solves the problem of slow page loading for the first time
我的创作纪念日
Navicat error: 1045-Access denied for user [email protected](using passwordYES)
1.2Recyclerview实现Item点击事件
[Flutter] Detailed explanation of the use of the Flutter inspector tool, viewing the Flutter layout, widget tree, debugging interface, etc.
Validation Framework-01
CMake Tutorial 巡礼(0)_总述
Nacos micro service ~ Nacos 】 【 configuration of the center
CAPL中的键值对(hash)数据类型
Tcp ip
npm ERR! code ENOTSUP npm ERR! notsup Unsupported engine for [email protected]: wanted: {“n
@RequestParam注解的详细介绍
手把手教你实现一个流动的渐变色边框
【微服务~Nacos】Nacos服务提供者和服务消费者
What majors become more popular the older they get?
[VMWARE--Shared files]
FlutterBoost 3.0出现 Activity无法转换为ExclusiveAppComponent<Activity>的解决办法