Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 58cc037

Browse files
add 2200
1 parent 6e75a93 commit 58cc037

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+
package com.fishercoder.solutions;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.List;
6+
7+
public class _2200 {
8+
public static class Solution1 {
9+
public List<Integer> findKDistantIndices(int[] nums, int key, int k) {
10+
List<Integer> ans = new ArrayList<>();
11+
List<Integer> keyIndices = new ArrayList<>();
12+
for (int i = 0; i < nums.length; i++) {
13+
if (nums[i] == key) {
14+
keyIndices.add(i);
15+
}
16+
}
17+
for (int i = 0; i < nums.length; i++) {
18+
for (int j = 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+
return ans;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)