문제
int 배열 nums[]와 target 정수가 주어진다.
nums[]를 오름차순으로 정렬한 후 nums[]에 있는 target 정수의 index를 list 형식으로 반환하라
https://leetcode.com/problems/find-target-indices-after-sorting-array/description/
풀이 방법
nums[]를 오름차순으로 정렬한다.
nums[]를 순회하며 target의 index를 찾고 list에 저장한다.
list를 반환한다.
class Solution { public List<Integer> targetIndices(int[] nums, int target) { List<Integer> list = new ArrayList<>(); // 1. 오름차순 정렬 Arrays.sort(nums); // 2. nums[] 순회하며 target index값 찾기 for (int i = 0; i < nums.length; i++) { if (nums[i] == target) { list.add(i); } } return list; } }
List 자료구조 정리
https://tojaman.tistory.com/52
오늘 회고
JAVA의 List에 대해 더욱 자세히 알게 되었다.
내일도 최선을 다하자.
'코딩 테스트 > 99클럽' 카테고리의 다른 글
[99클럽] 코테 스터디 33일차 TIL - 큐(1700. Number of Students Unable to Eat Lunch) (0) | 2024.06.22 |
---|---|
[99클럽] 코테 스터디 31일차 TIL - 정렬(2733. Neither Minimum nor Maximum) (0) | 2024.06.21 |
[99클럽] 코테 스터디 29일차 TIL - 문자열(1528. Shuffle String) (0) | 2024.06.18 |
[99클럽] 코테 스터디 28일차 TIL - 배열(1773. Count Items Matching a Rule) (0) | 2024.06.17 |
[99클럽] 코테 스터디 26일차 TIL - 배열(1512. Number of Good Pairs) (0) | 2024.06.15 |