Class Solution
-
- All Implemented Interfaces:
public final class Solution3452 - Sum of Good Numbers.
Easy
Given an array of integers
numsand an integerk, an elementnums[i]is considered good if it is strictly greater than the elements at indicesi - kandi + k(if those indices exist). If neither of these indices exists,nums[i]is still considered good.Return the sum of all the good elements in the array.
Example 1:
Input: nums = 1,3,2,1,5,4, k = 2
Output: 12
Explanation:
The good numbers are
nums[1] = 3,nums[4] = 5, andnums[5] = 4because they are strictly greater than the numbers at indicesi - kandi + k.Example 2:
Input: nums = 2,1, k = 1
Output: 2
Explanation:
The only good number is
nums[0] = 2because it is strictly greater thannums[1].Constraints:
2 <= nums.length <= 1001 <= nums[i] <= 10001 <= k <= floor(nums.length / 2)
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegersumOfGoodNumbers(IntArray nums, Integer k)-
-
Method Detail
-
sumOfGoodNumbers
final Integer sumOfGoodNumbers(IntArray nums, Integer k)
-
-
-
-