当前位置:网站首页>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;
}
};
边栏推荐
- ros(24):error: invalid initialization of reference of type ‘xx’ from expression of type ‘xx’
- Kubernetes 架构核心组件工作原理解析
- D manual destruction may violate memory security
- Previous basic review
- Realization of MNIST handwritten numeral recognition
- 5-minute NLP: summary of 3 pre training libraries for rapid realization of NER
- Activity startup process
- Leetcode 1248. 统计「优美子数组」(害,突然发现只会暴力枚举了)
- 2022年全国最新消防设施操作员(高级消防设施操作员)模拟题及答案
- A plug-in framework for implementing registration free and login verification with hook technology
猜你喜欢

Meta & Berkeley proposed a universal multi-scale visual transformer based on pooled self attention mechanism. The classification accuracy in Imagenet reached 88.8%! Open source

Use and click of multitypeadapter in recycleview

Custom animation (simulated win10 loading animation) - Optimization

Apk slimming compression experience

Wallpaper applet wechat applet

Unimportant tokens can be stopped in advance! NVIDIA proposes an efficient visual transformer network a-vit with adaptive token to improve the throughput of the model

Practical operation notes - notebook plus memory and ash cleaning

Tiktok wallpaper applet source code
Microsoft won the title of "leader" in the magic quadrant of Gartner industrial Internet of things platform again!

Decoupling pages and components using lifecycle
随机推荐
Custom animation (simulated win10 loading animation)
5-minute NLP: summary of 3 pre training libraries for rapid realization of NER
不重要的token可以提前停止计算!英伟达提出自适应token的高效视觉Transformer网络A-ViT,提高模型的吞吐量!...
移动安全工具-jarsigner
D manual destruction may violate memory security
Design and practice of vivo server monitoring architecture
How can I persuade leaders to use DDD to construct the liver project?
Punch smart spirit 1. The brand is attractive. What is the strength of the product?
移动安全工具-dex2jar
Microsoft won the title of "leader" in the magic quadrant of Gartner industrial Internet of things platform again!
VNC viewer remote connection raspberry pie without display
Go crawler framework -colly actual combat (IV) -- Zhihu answer crawl (I)
D does not require opapply() as a domain
ros(24):error: invalid initialization of reference of type ‘xx’ from expression of type ‘xx’
百公里加速仅5.92秒,威兰达高性能版以高能产品实力领跑
What is test development? Can you find a job at this stage?
Previous basic review (link)
How to quickly open traffic master for wechat applet
Scrollview height cannot fill full screen
Xcode preview displays a bug in the content of the list view and its solution