2 parents ddd7fe7 + a3dc6e8 commit 768bb40Copy full SHA for 768bb40
1 file changed
leetcode3/강병호/3452_Sum of Good Numbers.java
@@ -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
14
15
16
+ if (isGood) {
17
+ sum += nums[i];
18
19
20
21
+ return sum;
22
23
+}
0 commit comments