f '고득점 Kit' 태그의 글 목록 — 하늘속에서IT

고득점 Kit

    Programmers 이분탐색 :: 레벨3 :: 입국심사

    풀이 class Immigration { fun solution(n: Int, times: IntArray): Long{ var answer: Long = 0 times.sort() var start: Long = 0 var end: Long = times.last().toLong() * n /** * 특이점 * - while(start < end) 조건은 왜 불가능할까? * * 예를 통해 알아보자 * n : 6 * times : [7,10] * 만약 start : 28, end: 31 이라고 할때를 가정해보자 * start: 28, end: 31 * mid: 29 * end

    Programmers 스택/큐::레벨2::프린터

    풀이 import java.util.* class Solution { fun solution(priorities: IntArray, location: Int): Int { val operationQ: Queue = LinkedList() val standByQ: Queue = LinkedList(priorities.mapIndexed { index, priorityValue -> PrintTarget(index, priorityValue) }) /** 설명 - operationQ(실제 실행 대기열) 와 standByQ(실행 하기전 대기열) 두개의 큐를 선언한다. - 문제의 조건에 맞추어 standByQ 에서 operationQ 로 값을 이동시킨다. */ while(standByQ.isNotEmpty())..

    Programmers :: 해시 전화 번호 목록 레벨2

    풀이 import java.util.Arrays; class Solution { public boolean solution(String[] phone_book) { boolean answer = true; Arrays.sort(phone_book); for(int i=0;i< phone_book.length;i++){ if(i==phone_book.length-1) break; if(phone_book[i+1].startsWith(phone_book[i])){ answer = false; break; } } return answer; } } 출처 코딩테스트 연습 - 전화번호 목록 전화번호부에 적힌 전화번호 중, 한 번호가 다른 번호의 접두어인 경우가 있는지 확인하려 합니다. 전화번호가 다음과 같을 경우,..

    Programmers :: 정렬 가장 큰 수 레벨2

    풀이 class Solution { fun solution(numbers: IntArray): String { if(numbers.contentEquals(IntArray(numbers.size){0})) return "0" return numbers .map { it.toString().repeat(3) } .sortedByDescending { it } .map { it.slice(IntRange(0,it.length/3-1)) } .joinToString("") } } 출처 코딩테스트 연습 - 가장 큰 수 0 또는 양의 정수가 주어졌을 때, 정수를 이어 붙여 만들 수 있는 가장 큰 수를 알아내 주세요. 예를 들어, 주어진 정수가 [6, 10, 2]라면 [6102, 6210, 1062, 1026, 2..

    Programmers :: Heap(힙) 더 맵게 레벨2

    풀이 import java.util.Arrays; import java.util.PriorityQueue; import java.util.stream.Collectors; class Solution{ public int solution(int[] scoville, int K){ int count = 0; int firstLowest; int secondLowest; int combinedTwoLowestFoods; PriorityQueue priorityQueueLowest = new PriorityQueue(Arrays.stream(scoville).boxed().collect(Collectors.toList())); while(true){ if(priorityQueueLowest.size() == 1..

    Programmers :: DFS(깊이 우선 탐색법) 네트워크 레벨 3

    풀이 import java.util.* class Solution { fun solution(n: Int, computers: Array): Int { val graph = Graph(n, computers) graph.buildEdge( graph.computersToRelationList() ) return graph.getNetworkSize() } } class Graph(n: Int, computers: Array) { val N: Int = n val adj = Array(N) { LinkedList() } val computers = computers fun buildEdge(relationList: List) { relationList.forEach { relation -> this.adj..

    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 } /** * 설명 * - 체육복을 잃어버린 사람의 앞뒤를 확인한뒤 여벌이 있는 자의 체육복을 빌린다. * * 부연 설명(특이점) * - 첫번..