Algorithm/inflearn

장난꾸러기

마닐라 2021. 9. 27. 23:02

 

import java.util.*;

public class Main {

    public static ArrayList<Integer> solution(int n, int[] arr) {
        ArrayList<Integer> answer = new ArrayList<>();

        //원본 배열에 영향을 끼친다.,
        //int[] arr2 = arr;
        //Arrays.sort(arr2);
        //System.out.println(Arrays.toString(arr));

        int[] arr2 = arr.clone();
        Arrays.sort(arr2);

        for(int i = 0; i < n; i++) {
            if(arr[i] != arr2[i]) answer.add(i+1);
        }
        System.out.println(answer);

        return answer;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int[] arr1 = {120,125,152,130,135,135,143,127,160};
        int[] arr2 = {1,5,3,5,1,2,1,4};
        int[][] arr3 = {{3,4,1,2}, {4,3,2,1}, {3,1,4,2}};

        solution(9,arr1);

    }

}

'Algorithm > inflearn' 카테고리의 다른 글

이분검색  (0) 2021.09.27
좌표 정렬  (0) 2021.09.27
중복 확인  (0) 2021.09.27
★★LRU(캐시, 카카오 변형)  (0) 2021.09.27
삽입정렬  (0) 2021.09.20