Skip to content

Commit 768bb40

Browse files
Merge pull request #1676 from CodingTestStudy2/강병호
[강병호] Day16
2 parents ddd7fe7 + a3dc6e8 commit 768bb40

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public int sumOfGoodNumbers(int[] nums, int k) {
3+
int sum = 0;
4+
int n = nums.length;
5+
6+
for (int i = 0; i < n; i++) {
7+
boolean isGood = true;
8+
9+
if (i - k >= 0 && nums[i] <= nums[i - k]) {
10+
isGood = false;
11+
}
12+
if (i + k < n && nums[i] <= nums[i + k]) {
13+
isGood = false;
14+
}
15+
16+
if (isGood) {
17+
sum += nums[i];
18+
}
19+
}
20+
21+
return sum;
22+
}
23+
}

0 commit comments

Comments
 (0)