Skip to content

Commit 220fa26

Browse files
solves #2778: Sum of Squares of Special Elements in java
1 parent 0515813 commit 220fa26

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@
838838
| 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | [![Java](assets/java.png)](src/LongestEvenOddSubarrayWithThreshold.java) | |
839839
| 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | [![Java](assets/java.png)](src/LongestAlternatingSubarray.java) | |
840840
| 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | [![Java](assets/java.png)](src/FindTheMaximumAchievableNumber.java) | |
841-
| 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | | |
841+
| 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | [![Java](assets/java.png)](src/SumOfSquaresOfSpecialElements.java) | |
842842
| 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | | |
843843
| 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | | |
844844
| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | | |
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://leetcode.com/problems/sum-of-squares-of-special-elements
2+
// T: O(N)
3+
// S: O(1)
4+
5+
public class SumOfSquaresOfSpecialElements {
6+
public int sumOfSquares(int[] nums) {
7+
int result = 0;
8+
for (int i = 0 ; i < nums.length ; i++) {
9+
if (nums.length % (i + 1) == 0) {
10+
result += nums[i] * nums[i];
11+
}
12+
}
13+
return result;
14+
}
15+
}

0 commit comments

Comments
 (0)