728x90
반응형
✨ 문제
Find Targer Indices After Sorting Array
You are given a 0-indexed integer array nums and a target element target.
A target index is an index i such that nums[i] == target.
Return a list of the target indices of nums after sorting nums in non-decreasing order. If there are no target indices, return an empty list. The returned list must be sorted in increasing order.
https://leetcode.com/problems/find-target-indices-after-sorting-array/description/
✨ 최종코드
class Solution {
public List<Integer> targetIndices(int[] nums, int target) {
Arrays.sort(nums);
List<Integer> targetIndicesList = new ArrayList<>();
for (int i = 0; i < nums.length; i++) {
if (nums[i] == target) {
targetIndicesList.add(i);
}
}
return targetIndicesList;
}
}
728x90
반응형