정렬 3

[1주차] Coding Test 그리디/ 정렬/ 이분탐색/ 시뮬레이션

1. 기지국 설치 https://programmers.co.kr/learn/courses/30/lessons/12979 Sol 1) 기본형 이용- 정확성: 0.02ms, 효율성: 1.19ms // 기지국 설치 // https://programmers.co.kr/learn/courses/30/lessons/12979 import java.util.*; public class T3 { public static int solution(int n, int[] stations, int w) { // 16, [9], 2 int cnt = 0; // 기지국 개수 int position = 1; // 1동부터 시작 int idx = 0; // stations[] 내의 idx // 위치의 개념 position // 등호..

Chapter 06. Sorting and Searching (정렬, 이분검색과 결정알고리즘)

1. 선택정렬 import java.util.*; public class Main { public static void main(String[] args){ Main T = new Main(); Scanner in=new Scanner(System.in); int n = in.nextInt(); int[] arr = new int[n]; for(int i = 0; i< n; ++i){ arr[i] = in.nextInt(); } for(int x : T.solution(n, arr)){ System.out.print(x + " "); } } public int[] solution(int n, int[] arr){ for(int i = 0; i < n-1; ++i){ int idx = i; for(int ..

Part 07 정렬 (Sort)

Note) - 선형 자료구조 -> list, array - 정렬: 순서를 규칙에 맞게 바꾸는 것 1. Bubble sort - 크기를 비교해서 작은 것을 왼쪽에 둔다. - index 0 을 inde = 1 ~ n-1 까지의 값과 비교한다. - index 1 을 inde = 2 ~ n-1 까지의 값과 비교한다. ... - 시간 복잡도: O(n) - 가장 느리고 확실 import java.util.Comparator; import java.util.LinkedList; import java.util.List; public class BubbleSort implements Sortable { public List sort(List list , Comparator comparator){ List copy = n..