当前位置:网站首页>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;
}
};
边栏推荐
- 5-minute NLP: summary of 3 pre training libraries for rapid realization of NER
- Input series
- Databinding quick start (still using findviewbyid?)
- A small crawler program written by beginners
- Paper review: U2 net, u-net composed of u-net
- Mobile security tool -dex2jar
- 2022年危险化学品经营单位安全管理人员考试试题及模拟考试
- Mobile security tool jarsigner
- Infotnews | is the development of domestic NFT limited to digital collections?
- Kibana installation via kubernetes visual interface (rancher)
猜你喜欢
Network request -volley
iNFTnews | 国内NFT发展仅限于数字藏品吗?
[redis realizes seckill service ④] one order for one person, and cannot be purchased repeatedly
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
[microservices sentinel] cluster link | microservices cluster environment construction
How can I persuade leaders to use DDD to construct the liver project?
Infotnews | is the development of domestic NFT limited to digital collections?
Apk slimming compression experience
Technologie des fenêtres coulissantes en octets dans la couche de transmission
2022R1快开门式压力容器操作考题及答案
随机推荐
The basic principle and application of iterator and enhanced for
Use of JMeter
我想问一下兴业证券怎么开户?通过链接办理股票开户安全吗
[redis realizes seckill service ②] solution to oversold problem
Apk decompiled method (not confused)
[leaderboard] Carla leaderboard leaderboard leaderboard operation and participation in hands-on teaching
Go crawler framework -colly actual combat (III) -- panoramic cartoon picture capture and download
Design scheme of authority management of fusion model
Go crawler framework -colly actual combat (II) -- Douban top250 crawling
Outer screen and widescreen wasted? Harmonyos folding screen design specification teaches you to use it
Domain Driven Design and coding
The problem of multiple callback of video ads stimulated by applets (offcolse problem)
傳輸層 以字節為單比特的滑動窗口技術
EVM简略
[redis realizes seckill business ③] specific implementation of optimistic lock for oversold problem
Mobile security tool apktool
Paint rounded rectangle
Qiniu cloud uploads video to get the first frame of video
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
生成订单30分钟未支付,则自动取消,该怎么实现?