Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit57ef53d

Browse files
authored
Merge pull requestneetcode-gh#1344 from julienChemillier/patch-31
Add 209 in c language
2 parents59f1fd2 +299ddca commit57ef53d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎c/209-Minimum-Size-Subarray-Sum.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Given an array of positive integers nums and a positive integer target, return
3+
the minimal length of a contiguous subarray of which the sum is greater than or
4+
equal to target
5+
6+
Space: O(1)
7+
Time: O(n)
8+
*/
9+
10+
intmin(inta,intb) {
11+
returna<b?a:b;
12+
}
13+
14+
intminSubArrayLen(inttarget,int*nums,intnumsSize){
15+
intlen=0;
16+
inti=0,j=0;
17+
intcpt=0;
18+
while (j<numsSize) {
19+
cpt+=nums[j];
20+
if (cpt>=target) {
21+
if (len==0)
22+
len=j-i+1;
23+
while (cpt-nums[i] >=target) {
24+
cpt-=nums[i];
25+
len=min(len,j-i);
26+
i++;
27+
}
28+
}
29+
j++;
30+
}
31+
returnlen;
32+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp