当前位置:网站首页>Leetcode 1248. Statistics of "graceful subarray" (harm, suddenly found that it can only enumerate violently)
Leetcode 1248. Statistics of "graceful subarray" (harm, suddenly found that it can only enumerate violently)
2022-06-25 00:57:00 【I'm not xiaohaiwa~~~~】
Give you an array of integers nums And an integer k. If there happens to be... In a continuous subarray k It's an odd number , We think that this subarray is 「 Graceful subarray 」.
Please return to this array 「 Graceful subarray 」 Number of .
Example 1:
Input :nums = [1,1,2,1,1], k = 3
Output :2
explain : contain 3 An odd subarray is [1,1,2,1] and [1,2,1,1] .
Example 2:
Input :nums = [2,4,6], k = 1
Output :0
explain : There are no odd numbers in the sequence , So there's no graceful subarray .
Example 3:
Input :nums = [2,2,2,1,2,2,1,2,2,2], k = 2
Output :16
Tips :
- 1 <= nums.length <= 50000
- 1 <= nums[i] <= 10^5
- 1 <= k <= nums.length
Code:
class Solution {
public:
int numberOfSubarrays(vector<int>& nums, int k) {
int res=0;
for(int i=0;i<nums.size();i++)
{
int cnt=0;
for(int j=i;j<nums.size();j++)
{
if(nums[j]%2)
{
cnt++;
}
if(cnt>k)
{
break;
}
if(cnt==k)
{
res++;
}
}
}
cout<<res<<endl;
return res;
}
};
边栏推荐
- Mobile security tool jarsigner
- Go crawler framework -colly actual combat (II) -- Douban top250 crawling
- [Solved] Public key for mysql-community-xxx. rpm is not installed
- 2021-09-12
- Apk decompiled method (not confused)
- 不重要的token可以提前停止计算!英伟达提出自适应token的高效视觉Transformer网络A-ViT,提高模型的吞吐量!...
- placeholder
- Custom animation (simulated win10 loading animation)
- Paint rounded rectangle
- 108页(4万字)未来公寓智能化设计平台项目方案建议书2022版
猜你喜欢

Apk slimming compression experience

Registration method of native method in JNI

Custom animation (simulated win10 loading animation)

2022R1快开门式压力容器操作考题及答案

Xcode预览(Preview)显示List视图内容的一个Bug及解决

The interview questions and answers for the high-frequency software test of Dachang help you prepare for the golden nine silver ten

Working principle analysis of kubernetes architecture core components

传输层 以字节为单位的滑动窗口技术

VNC viewer remote connection raspberry pie without display

Binder mechanism and Aidl communication example
随机推荐
How to use promise Race() and promise any() ?
WordPress add photo album function [advanced custom fields Pro custom fields plug-in series tutorial]
Fuxin Kunpeng joins in, and dragon lizard community welcomes a new partner in format document technical service
December 6, 2019 what happens after the browser enters a URL
Hyperledger Fabric 2. X dynamic update smart contract
我想问一下兴业证券怎么开户?通过链接办理股票开户安全吗
More pictures | explain the Nacos parameters in detail!
Meta&伯克利基于池化自注意力机制提出通用多尺度视觉Transformer,在ImageNet分类准确率达88.8%!开源...
Leetcode 1248. 统计「优美子数组」(害,突然发现只会暴力枚举了)
Xcode preview displays a bug in the content of the list view and its solution
Applet opening traffic master
2022熔化焊接与热切割复训题库模拟考试平台操作
Practical operation notes - notebook plus memory and ash cleaning
Previous basic review
Jar package merging using Apache ant
[Solved] Public key for mysql-community-xxx. rpm is not installed
adb shell getevent
Mobile security tool -dex2jar
Single blind box removal, social blind box and friend blind box program source code
Some examples of MgO operating database in go