분류 전체보기
-
프로그래머스 - 더 맵게알고리즘 문제 풀이 2020. 9. 7. 22:19
package programmers.heap; /* * 2020-09-07 * https://programmers.co.kr/learn/courses/30/lessons/42626?language=java */ import java.util.PriorityQueue; import java.util.concurrent.atomic.AtomicBoolean; public class MoreSpicy { public int solution(int[] scoville, int K) { PriorityQueue scovilleQueue = new PriorityQueue(); for (int i = 0; i < scoville.length; i++) { scovilleQueue.add(scoville[i]); }..
-
프로그래머스 - 카펫카테고리 없음 2020. 9. 2. 22:10
import kotlin.test.assertEquals /* * 2020-09-02 * https://programmers.co.kr/learn/courses/30/lessons/42842 */ class Carpet { fun solution(brown: Int, yellow: Int): IntArray { var answer = intArrayOf() for (i in 1..yellow) { for (j in 1..yellow) { if (i >= j && i * j == yellow && (i + 2) * (j + 2) - yellow == brown) { return intArrayOf(i + 2, j + 2) } } } return answer } } fun main(args: Array) {..
-
프로그래머스 - 소수 찾기알고리즘 문제 풀이 2020. 9. 2. 21:30
import kotlin.test.assertEquals /* * 2020-09-02 * https://programmers.co.kr/learn/courses/30/lessons/42839 */ class FindPrimeNumber { fun solution(numbers: String): Int { val numberValues = numbers.map { it.toString() } val numbersGroup = numbers.groupBy { it } val numberList = ArrayList() val newNumberList = ArrayList() for (i in 0 until numbers.count()) { if (numberList.isEmpty()) { numberValu..
-
프로그래머스 - 모의고사알고리즘 문제 풀이 2020. 8. 24. 21:53
/* * 2020-08-24 * https://programmers.co.kr/learn/courses/30/lessons/42840 */ class PracticeTest { fun solution(answers: IntArray): IntArray { val first = listOf(1, 2, 3, 4, 5) val second = listOf(2, 1, 2, 3, 2, 4, 2, 5) val third = listOf(3, 3, 1, 1, 2, 2, 4, 4, 5, 5) var firstCnt = 0 var secondCnt = 0 var thirdCnt = 0 answers.forEachIndexed { i, answer -> if (answer == first[i % first.count()]..
-
프로그래머스 - 프린터알고리즘 문제 풀이 2020. 8. 23. 12:33
import java.util.LinkedList /* * 2020-08-23 * https://programmers.co.kr/learn/courses/30/lessons/42587 */ class Printer { fun solution(priorities: IntArray, location: Int): Int { val queue = LinkedList(priorities.toList()) var index = location var answer = 1 while (!queue.isEmpty()) { val priority = queue.pop() val checkPriority = queue.find { it > priority } if (checkPriority !== null) { // 가장 ..
-
프로그래머스 - 다리를 지나는 트럭알고리즘 문제 풀이 2020. 8. 8. 20:37
/* * 2020-08-08 * https://programmers.co.kr/learn/courses/30/lessons/42583 */ class TruckPassingTheBridge { fun solution(bridge_length: Int, weight: Int, truck_weights: IntArray): Int { var passingList = ArrayList() var time = 0 val truckList = truck_weights.toMutableList() var truck = truckList.removeAt(0) do { time++ passingList = passingList.filter { truckPair -> truckPair.second < bridge_len..
-
프로그래머스 - 기능개발알고리즘 문제 풀이 2020. 8. 5. 23:09
import kotlin.math.ceil /* * 2020-08-05 * https://programmers.co.kr/learn/courses/30/lessons/42586?language=kotlin */ class FunctionDevelopment { fun solution(progresses: IntArray, speeds: IntArray): IntArray { var answer = ArrayList() val workingDays = progresses.mapIndexed { i, progress -> ceil((100-progress).div(speeds[i].toDouble())).toInt() } var prevWork = workingDays.first() var cnt = 1 w..