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

Commit b659134

Browse files
authored
Create Find Target Indices After Sorting Array.java
1 parent 9e1aad7 commit b659134

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public List<Integer> targetIndices(int[] nums, int target) {
3+
int count = 0;
4+
int lessThanCount = 0;
5+
for (int num : nums) {
6+
if (num == target) {
7+
count++;
8+
}
9+
if (num < target) {
10+
lessThanCount++;
11+
}
12+
}
13+
List<Integer> indices = new ArrayList<>();
14+
for (int i = 0; i < count; i++) {
15+
indices.add(lessThanCount + i);
16+
}
17+
return indices;
18+
}
19+
}

0 commit comments

Comments
 (0)