코딩테스트 준비(kotlin)/자료구조11 [프로그래머스 , kotlin] 이중우선순위큐 import java.util.Collectionsimport java.util.PriorityQueuefun solution(operations: Array): IntArray { val minPriorityQueue = PriorityQueue() val maxPriorityQueue = PriorityQueue(Collections.reverseOrder()) val entryCount = mutableMapOf() //각 숫자의 개수를 저장하는 맵 for (i in operations.indices) { val value = operations[i].split(" ") val operation = value[0] val num = valu.. 2024. 8. 1. [kotlin, 프로그래머스] 베스트앨범 //프로그래머스 - 베스트앨범fun solution(genres: Array, plays: IntArray): IntArray { // 장르별 총 재생 횟수 val genrePlayCount = mutableMapOf() // 장르별 노래 목록 val genreMusics = mutableMapOf>>() for (i in genres.indices) { val genre = genres[i] val play = plays[i] // 장르별 총 재생 횟수 갱신 - 장르를 키 값으로 해서 재생횟수 갱신 genrePlayCount[genre] = genrePlayCount.getOrDefault(genre, 0) + play .. 2024. 7. 31. [프로그래머스 kotlin] 다리를 지나는 트럭 fun solution(bridge_length: Int, weight: Int, truck_weights: IntArray): Int { var answer = 0 val truckQueue: Queue = LinkedList() val bridge: Queue = LinkedList() // 초기 다리는 빈 공간으로 채웁니다. for (i in 0 until bridge_length) { bridge.add(0) } // truck_weights 배열의 트럭을 truckQueue에 추가 for (i in truck_weights.indices) { truckQueue.add(truck_weights[i]) } var cur.. 2024. 7. 9. [프로그래머스 kotlin] 롤케이크 자르기 시간 초과 발생 코드 fun solution(topping: IntArray): Int { var count=0 for(i in topping.indices){ val set1 = mutableSetOf() val set2 = mutableSetOf() for(j in 0.. i){ set1.add(topping[j]) } for(k in i+1 until topping.size){ set2.add(topping[k]) } if(set1.size==set2.size){ count++ } } println(count) .. 2024. 7. 1. 이전 1 2 3 다음