코딩 테스트/leetcode
Find Target Indices After Sorting Array
ornni
2024. 7. 29. 10:00
728x90
반응형
첫번째 코드
먼저 순서대로 정렬을 한 후에
target값과 동일한 경우 해당 인덱스를 가져오는 코드를 작성한다.
class Solution:
def targetIndices(self, nums: List[int], target: int) -> List[int]:
answer = []
nums.sort()
index = 0
for i in nums:
if i == target:
answer.append(index)
index += 1
return answer
통과
링크
https://github.com/ornni/leetcode/tree/main/2089-find-target-indices-after-sorting-array
leetcode/2089-find-target-indices-after-sorting-array at main · ornni/leetcode
Collection of LeetCode questions to ace the coding interview! - Created using [LeetHub v3](https://github.com/raphaelheinz/LeetHub-3.0) - ornni/leetcode
github.com
반응형