주녘공부일지

[프로그래머스 C#] Lv.2 기능개발 본문

Programmers - C#/CodingTest Lv.2

[프로그래머스 C#] Lv.2 기능개발

주녘 2023. 9. 3. 18:51
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/42586

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

1. 정답코드 및 핵심 아이디어, 유의사항

- 뒤에 있는 기능이 앞에 있는 기능보다 먼저 배포가 가능해도 순서대로 배포

 -> 배포까지 걸리는 기간을 Queue에 순서대로 넣고, 맨 앞에 있는 값을 기준으로 지워나가면서 같거나 작은 수는 한번에 배포가 가능함을 체크

https://godgjwnsgur7.tistory.com/46

 

[C#] 자료구조 정리 (Dict, List, Queue, Stack, HashSet 등)

자료구조(Data Structure)란? 데이터를 효율적으로 접근하고 조작할 수 있게 데이터 구조를 만들어 관리하는 것 - Collections은 C#에서 지원하는 자료구조 클래스 using System.Collections.Generic; 제네릭 컬렉

godgjwnsgur7.tistory.com

    using System;
    using System.Collections.Generic;

    public class Solution
    {
        public int[] solution(int[] progresses, int[] speeds)
        {
            List<int> answerList = new List<int>();
            Queue<int> queue = new Queue<int>();

            // 배포까지 걸리는 기간을 queue에 담음
            for (int i = 0; i < progresses.Length; i++)
            {
                int count = 1;
                while (progresses[i] + (speeds[i] * count) < 100)
                    count++;

                queue.Enqueue(count);
            }

            // 배포 가능 체크
            while (queue.Count > 0)
            {
                int count = 1; // 한번에 배포 가능한 개수
                int num = queue.Dequeue(); // 배포 가능 체크 기준
                
                // 배포 가능 개수 카운트
                while (queue.Count > 0 && queue.Peek() <= num)
                {
                    queue.Dequeue();
                    count++;
                }
                
                answerList.Add(count);
            }
            return answerList.ToArray();
        }
    }
728x90