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

Commit58cc037

Browse files
add 2200
1 parent6e75a93 commit58cc037

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|-------------|-------------
11+
| 2200|[Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2200.java)|| Easy||
1112
| 2194|[Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2194.java)|| Easy||
1213
| 2190|[Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2190.java)|| Easy||
1314
| 2186|[Minimum Number of Steps to Make Two Strings Anagram II](https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram-ii/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2186.java)|| Medium||
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.ArrayList;
4+
importjava.util.Collections;
5+
importjava.util.List;
6+
7+
publicclass_2200 {
8+
publicstaticclassSolution1 {
9+
publicList<Integer>findKDistantIndices(int[]nums,intkey,intk) {
10+
List<Integer>ans =newArrayList<>();
11+
List<Integer>keyIndices =newArrayList<>();
12+
for (inti =0;i <nums.length;i++) {
13+
if (nums[i] ==key) {
14+
keyIndices.add(i);
15+
}
16+
}
17+
for (inti =0;i <nums.length;i++) {
18+
for (intj =0;j <keyIndices.size();j++) {
19+
if (Math.abs(i -keyIndices.get(j)) <=k) {
20+
ans.add(i);
21+
break;
22+
}
23+
}
24+
}
25+
Collections.sort(ans);
26+
returnans;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp