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

Commit0cdc715

Browse files
authored
Fixed spacing
1 parent8413cf7 commit0cdc715

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

‎csharp/1343-number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 4. We will iterate through the array and calculate the sum of the next k element
1414
*/
1515
publicclassSolution{
1616
publicintNumOfSubarrays(int[]arr,intk,intthreshold){
17-
inti,j,c,res,sum;// Initialize i, j, c, res, and sum to 0.
17+
inti,j,c,res,sum;// Initialize i, j, c, res, and sum to 0.
1818
i=c=sum=res=0;// Initialize i, c, sum, and res to 0.
1919
j=i+k-1;// Initialize j to i + k - 1.
2020

@@ -23,18 +23,18 @@ public int NumOfSubarrays(int[] arr, int k, int threshold) {
2323
c++;// Increment c.
2424
}
2525

26-
res=(sum/k)>=threshold?1:0;// Check if the average is greater than or equal to the threshold and increment the result accordingly.
26+
res=(sum/k)>=threshold?1:0;// Check if the average is greater than or equal to the threshold and increment the result accordingly.
2727

28-
while(j<arr.Length){// Iterate through the array and calculate the sum of the next k elements.
28+
while(j<arr.Length){// Iterate through the array and calculate the sum of the next k elements.
2929
sum=sum-arr[i++];// Subtract the element at index i from the sum and increment i.
3030
j++;// Increment j.
31-
if(j<arr.Length){// Check if j is less than the length of the array.
31+
if(j<arr.Length){// Check if j is less than the length of the array.
3232
sum=sum+arr[j];// Add the element at index j to the sum.
3333
}
3434
else{
3535
break;// Break the loop if j is equal to or greater than the length of the array.
3636
}
37-
if((sum/k)>=threshold){// Check if the average is greater than or equal to the threshold.
37+
if((sum/k)>=threshold){// Check if the average is greater than or equal to the threshold.
3838
res++;// Increment the result.
3939
}
4040
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp