Skip to content

Commit 149643d

Browse files
add 2913
1 parent 4f44456 commit 149643d

File tree

3 files changed

+54
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src

3 files changed

+54
-0
lines changed

paginated_contents/algorithms/3rd_thousand/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
| 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2965.java) | | Easy |
77
| 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2942.java) | | Easy |
88
| 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2937.java) | | Easy |
9+
| 2913 | [Subarrays Distinct Element Sum of Squares I](https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2913.java) | | Easy |
910
| 2908 | [Minimum Sum of Mountain Triplets I](https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2908.java) | | Easy |
1011
| 2903 | [Find Indices With Index and Value Difference I](https://leetcode.com/problems/find-indices-with-index-and-value-difference-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2903.java) | | Easy |
1112
| 2900 | [Longest Unequal Adjacent Groups Subsequence I](https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2900.java) | | Easy |
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
import java.util.HashSet;
4+
import java.util.List;
5+
import java.util.Set;
6+
7+
public class _2913 {
8+
public static class Solution1 {
9+
public int sumCounts(List<Integer> nums) {
10+
int ans = 0;
11+
int subArraySize = 1;
12+
while (subArraySize <= nums.size()) {
13+
for (int i = 0; i < nums.size(); i++) {
14+
Set<Integer> set = new HashSet<>();
15+
set.add(nums.get(i));
16+
int j = i + 1;
17+
for (; j < Math.min(i + subArraySize, nums.size()); j++) {
18+
set.add(nums.get(j));
19+
}
20+
if (j - i == subArraySize) {
21+
ans += set.size() * set.size();
22+
}
23+
}
24+
subArraySize++;
25+
}
26+
return ans;
27+
}
28+
}
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2913;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.util.Arrays;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
11+
public class _2913Test {
12+
private static _2913.Solution1 solution1;
13+
14+
@BeforeEach
15+
public void setup() {
16+
solution1 = new _2913.Solution1();
17+
}
18+
19+
@Test
20+
public void test1() {
21+
assertEquals(15, solution1.sumCounts(Arrays.asList(1, 2, 1)));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)