반응형
Theo, 테오
시행착오를 줄이는 방법 - 진태양
Theo, 테오
  • 분류 전체보기 (82)
    • General (28)
      • Essay (22)
      • Craftsmanship (2)
      • IT Meet & Hack (4)
    • Finance (1)
      • Portfolio (1)
      • Activity (0)
    • Infrastructure (1)
      • Kubernetes (0)
      • AWS (1)
    • Development (45)
      • News (4)
      • Architecture (4)
      • Web (1)
      • Spring Framework (7)
      • JVM (12)
      • MongoDB (0)
      • Git (2)
      • Algorithm (14)
      • Python (1)
    • Computer Science (1)
      • Network (1)
    • Civic Hacking (3)
      • Code for Korea (3)
    • Know-how (2)
      • IT Service (1)
      • Career (1)
    • English (1)
      • Translation (1)

인기 글

  • [Java & Kotlin] enum class가 완벽한 ⋯
    2021.12.13
    [Java & Kotlin] enum class가 완벽한 ⋯
  • Why DDD, Clean Architecture and ⋯
    2022.03.10
    Why DDD, Clean Architecture and ⋯
  • SpringBoot에서 STOMP로 채팅 애플리케이션 만들⋯
    2021.12.13
    SpringBoot에서 STOMP로 채팅 애플리케이션 만들⋯
  • [번역] 개발자가 잠자는 동안 돈을버는 5가지 방법 | 사⋯
    2022.04.17
    [번역] 개발자가 잠자는 동안 돈을버는 5가지 방법 | 사⋯
  • SpringBoot에서 STOMP로 채팅 애플리케이션 만들⋯
    2021.12.14
    SpringBoot에서 STOMP로 채팅 애플리케이션 만들⋯

블로그 메뉴

  • 홈
  • 관리
  • 방명록
hELLO · Designed By 정상우.
Theo, 테오

시행착오를 줄이는 방법 - 진태양

[프로그래머스 코딩 테스트 연습] 스택/큐 - 프린터 (코틀린)
Development/Algorithm

[프로그래머스 코딩 테스트 연습] 스택/큐 - 프린터 (코틀린)

2021. 10. 13. 01:33
반응형

https://programmers.co.kr/learn/courses/30/lessons/42587?language=kotlin

 

코딩테스트 연습 - 프린터

일반적인 프린터는 인쇄 요청이 들어온 순서대로 인쇄합니다. 그렇기 때문에 중요한 문서가 나중에 인쇄될 수 있습니다. 이런 문제를 보완하기 위해 중요도가 높은 문서를 먼저 인쇄하는 프린

programmers.co.kr

data class Document(
    val priority: Int,
    val isTarget: Boolean
)

class Solution {
    fun solution(priorities: IntArray, location: Int): Int {
        var answer = 0
        
        val documents = priorities.mapIndexed { idx, priority ->
            Document(
                priority,
                if (location==idx) {
                    true
                } else {
                    false
                }
            )
        }.toMutableList()
        
        while(true) {
            var found:Boolean = false
            val firstDocument = documents.removeAt(0)
            var highestPriority = firstDocument.priority
            
            documents.forEach { document -> 
                if (document.priority > highestPriority) {
                    found = true
                    return@forEach
                }
            }
            
            if (found) {
                documents.add(firstDocument)
            } else {
                answer += 1
                if (firstDocument.isTarget) {
                    return answer
                }
            }
        }
    }
}

 

반응형
저작자표시 비영리 동일조건

    ☕️ Networking

    기술 직군의 기술적인 교류, 커리어 이야기, 직군 무관 네트워킹 모두 환영합니다!

    위클리 아카데미 오픈 채팅방(비밀번호: 9323)

    kakaotalk: https://open.kakao.com/o/gyvuT5Yd

    'Development/Algorithm' 카테고리의 다른 글
    • [LeetCode] 198. House Robber (Kotlin)
    • [LeetCode] 20. Valid Parentheses (Kotlin)
    • [LeetCode] 14. Longest Common Prefix (Kotlin)
    • [LeetCode] 13. Roman to Integer (Kotlin)
    알고리즘, 카카오 코테, 코딩테스트, 코틀린, 토스, 프로그래머스
    Theo, 테오
    Theo, 테오
    Java/Kotlin, Spring 백엔드 관련 기술을 익히고 공유합니다.
    [LeetCode] 13. Roman to Integer (Kotlin)
    다음 글
    [LeetCode] 13. Roman to Integer (Kotlin)

    티스토리툴바