###### tags: `leetcode`
# leecode 2089
題目:輸入一list nums, 及一target, 目標先對nums排列,再找出在nums中target的索引, 以list輸出
Example 1:
Input: nums = [1,2,5,2,3], target = 2
Output: [1,2]
Explanation: After sorting, nums is [1,2,2,3,5].
The indices where nums[i] == 2 are 1 and 2.
Example 2:
Input: nums = [1,2,5,2,3], target = 3
Output: [3]
Explanation: After sorting, nums is [1,2,2,3,5].
The index where nums[i] == 3 is 3.
Example 3:
Input: nums = [1,2,5,2,3], target = 5
Output: [4]
Explanation: After sorting, nums is [1,2,2,3,5].
The index where nums[i] == 5 is 4.
```
class Solution:
def targetIndices(self, nums: List[int], target: int) -> List[int]:
nums.sort() #in python, there is exist sort function, which complexity is O(NlogN)
a=[i for i in range(len(nums)) if nums[i]==target]
return a
```
這邊的sort()是python內建函式,應該是quick sort或merge sort,複雜度為O(NlogN)
下一行是for loop索引,內包一if判斷是不是target,然後做list
再來輸出即可