Skip to content

Commit 0a5201f

Browse files
solves find target indices after sorting array
1 parent d896a22 commit 0a5201f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@
495495
| 2073 | [Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets) | [![Java](assets/java.png)](src/TimeNeededToBuyTickets.java) | |
496496
| 2078 | [Two Furthest Houses With Different Colors](https://leetcode.com/problems/two-furthest-houses-with-different-colors) | [![Java](assets/java.png)](src/TwoFurthestHousesWithDifferentColors.java) | |
497497
| 2085 | [Count Common Words With One Occurrence](https://leetcode.com/problems/count-common-words-with-one-occurrence) | [![Java](assets/java.png)](src/CountCommonWordsWithOneOccurrence.java) | |
498-
| 2089 | [Find Target Indices After Sorting Array](https://leetcode.com/problems/find-target-indices-after-sorting-array) | | |
498+
| 2089 | [Find Target Indices After Sorting Array](https://leetcode.com/problems/find-target-indices-after-sorting-array) | [![Java](assets/java.png)](src/FindTargetIndicesAfterSortingArray.java) | |
499499
| 2094 | [Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers) | | |
500500
| 2099 | [Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum) | | |
501501
| 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | | |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.util.ArrayList;
2+
import java.util.Arrays;
3+
import java.util.List;
4+
5+
public class FindTargetIndicesAfterSortingArray {
6+
public List<Integer> targetIndices(int[] nums, int target) {
7+
Arrays.sort(nums);
8+
final List<Integer> indices = new ArrayList<>();
9+
for (int i = 0 ; i < nums.length ; i++) {
10+
if (nums[i] == target) {
11+
indices.add(i);
12+
}
13+
}
14+
return indices;
15+
}
16+
}

0 commit comments

Comments
 (0)