2021/01
-
자바8 - 다양한 정렬 방법카테고리 없음 2021. 1. 24. 23:09
Comparator 를 이용한 정렬익명 클래스를 이용한 정렬람다를 활용한 정렬comparing 메소드를 이용한 정렬메소드 참조를 이용한 정렬결론참조JDK 1.8 이상 사용을 기준으로 하는 내용입니다.class Apple{ private int weight; Apple(int weight) { this.weight = weight; } public int getWeight() { return weight; } public void setWeight(int weight) { this.weight = weight; } }위와 같은 Apple 클래스를 이용하여 간단한 정렬을 하겠습니다.List list = Arrays.asList(new Apple(200), new Apple(100), new Apple(150..
-
프로그래머스 - 여행 경로알고리즘 문제 풀이 2021. 1. 17. 00:46
/* * 2021-01-17 * https://programmers.co.kr/learn/courses/30/lessons/43164?language=kotlin */ fun travelRoute(tickets: Array): Array { // route 를 맵으로 생성 val routeMap = mutableMapOf() tickets.forEach { val start = it[0] val dest = it[1] val routeString = "$start-$dest" val route = routeMap[routeString] if (route == null) { routeMap[routeString] = Route(start, dest, 0, emptyList(), 1) } else { rou..
-
프로그래머스 - 단어 변환알고리즘 문제 풀이 2021. 1. 2. 00:14
/* * 2021-01-01 * https://programmers.co.kr/learn/courses/30/lessons/43163 */ fun wordConversion(begin: String, target: String, words: Array): Int { // words 에 target 이 없는 경우 0 반환 if (!words.any { it == target }) { return 0 } // begin 을 포함한 allWords 생성 val allWords = words.plus(begin) // 각 단어별 노드 생성 val nodeMap = allWords.associate { it to WordNode(it) } nodeMap.forEach { (word, node) -> // 한글자만..