f '탐욕법' 태그의 글 목록 — 하늘속에서IT

탐욕법

    Programmers :: Greedy(탐욕법) 체육복 레벨1

    풀이 class Solution { fun solution(n: Int, lost: IntArray, reserve: IntArray): Int { // 학생들의 체육복 default 갯수 val students = IntArray(n) { 1 } // 학생들중 체육복을 잃어버린 사람 lost.forEach { los -> students[los - 1] = students[los - 1] - 1 } // 학생들중 체육복 여벌을 가지고 있는 사람 reserve.forEach { res -> students[res - 1] = students[res - 1] + 1 } /** * 설명 * - 체육복을 잃어버린 사람의 앞뒤를 확인한뒤 여벌이 있는 자의 체육복을 빌린다. * * 부연 설명(특이점) * - 첫번..