当前位置:网站首页>Leetcode · 83 biweekly race · 6129. Number of all 0 subarrays · mathematics
Leetcode · 83 biweekly race · 6129. Number of all 0 subarrays · mathematics
2022-07-25 08:42:00 【Xiao Xun wants to be strong】
link :https://leetcode.cn/problems/number-of-zero-filled-subarrays/solution/mei-you-by-xun-ge-v-wokp/
source : Power button (LeetCode)
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .
subject

Example

Ideas
Their thinking
mathematics
n individual 0 Energy composition n The total factorial of 0 The string of
There is no algorithm , Only routine , You only need to know the above to solve it
Concrete realization
Traversal array , Statistics 0 Substring length
Then add the substring length after full factorial
Return the last accumulated value
Code
long long zeroFilledSubarray(int* nums, int numsSize){
long long sum = 0;
long long m = 0;
for(int i = 0; i < numsSize; i++)// Traversal array , Judge 0 The number of
{
if(nums[i] == 0)
{
m++;
}
else
{
while(m)// seek m Factorial of and then accumulate
{
sum += m;
m--;
}
}
}
while(m)
{
sum += m;
m--;
}
return sum;
}
author :xun-ge-v
link :https://leetcode.cn/problems/number-of-zero-filled-subarrays/solution/mei-you-by-xun-ge-v-wokp/
source : Power button (LeetCode)
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .Time and space complexity

边栏推荐
- LeetCode·83双周赛·6129.全0子数组的数目·数学
- 【黑马程序员】Redis学习笔记005:企业级解决方案
- Talk about your transformation test development process
- @Autowired的使用
- Apartment repair reporting system (idea, SSM, MySQL)
- The international summit osdi included Taobao system papers for the first time, and end cloud collaborative intelligence was recommended by the keynote speech of the conference
- RTOS series (13): assembly LDR instruction, LDR pseudo instruction, [rn] register indirect reference detailed analysis
- 为什么要使用MQ消息中间件?这几个问题必须拿下!
- Rstudio shows that it can't connect to the web page, or it has a new website.
- read
猜你喜欢

Graduation project of wechat small program ordering system of small program completion works (6) opening defense ppt

Redis learning

华为设备远程登录(Telnet、SSH)配置

递归调用实现打印一个整数的每一位

记录两次多端排查问题的过程

这是我见过写得最烂的Controller层代码...

Chapter 3 business function development (query clues)

Some easy-to-use plug-ins and settings installed in vscode

Wechat reservation applet graduation design of applet completion works (2) applet function

【万字长文】使用 LSM-Tree 思想基于.Net 6.0 C# 实现 KV 数据库(案例版)
随机推荐
递归调用实现打印一个整数的每一位
RTOS系列(13):汇编LDR指令、LDR伪指令、[Rn]寄存器间接引用 详细解析
【keras bug】Tensor is unhashable if Tensor equality is enabled. Instead, use tensor.experimental_ ref(
Database query optimization
Refreshing mobile terminal personal center page
A simple hotel background management system based on jsp+servlet+mysql
Redis fragment cluster
The international summit osdi included Taobao system papers for the first time, and end cloud collaborative intelligence was recommended by the keynote speech of the conference
Centernet network structure construction
Idea2021 failed to start. Could not find main class com/intellij/idea/main
OpenGL es to achieve the effect of "big head, small head" and "head shaking"
Fundamentals of C language
Practice of establishing dynamic programming state transition equation
Intelligent operation and maintenance scenario analysis: how to detect abnormal business system status through exception detection
Some easy-to-use plug-ins and settings installed in vscode
Summary of SQL skills in data warehouse development
unity客户端读取文本配置
Redis best practices
25 Ph.D. degrees revoked
Initial knowledge of WebService (generate jar packages and call methods in remote services)