Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit149643d

Browse files
add 2913
1 parent4f44456 commit149643d

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+
packagecom.fishercoder.solutions.thirdthousand;
2+
3+
importjava.util.HashSet;
4+
importjava.util.List;
5+
importjava.util.Set;
6+
7+
publicclass_2913 {
8+
publicstaticclassSolution1 {
9+
publicintsumCounts(List<Integer>nums) {
10+
intans =0;
11+
intsubArraySize =1;
12+
while (subArraySize <=nums.size()) {
13+
for (inti =0;i <nums.size();i++) {
14+
Set<Integer>set =newHashSet<>();
15+
set.add(nums.get(i));
16+
intj =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+
returnans;
27+
}
28+
}
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
packagecom.fishercoder.thirdthousand;
2+
3+
importcom.fishercoder.solutions.thirdthousand._2913;
4+
importorg.junit.jupiter.api.BeforeEach;
5+
importorg.junit.jupiter.api.Test;
6+
7+
importjava.util.Arrays;
8+
9+
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
10+
11+
publicclass_2913Test {
12+
privatestatic_2913.Solution1solution1;
13+
14+
@BeforeEach
15+
publicvoidsetup() {
16+
solution1 =new_2913.Solution1();
17+
}
18+
19+
@Test
20+
publicvoidtest1() {
21+
assertEquals(15,solution1.sumCounts(Arrays.asList(1,2,1)));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp