Lv 2. 기능개발

2024. 6. 10. 15:30·Algorithm & Data Structures/Programers

 

이번문제는 queue에다가 기능개발에 소요되는 각각의 기능들의 소요일수를 저장 해 놓고 하나씩 빼보며 몇개를 연속으로 뺄 수 있나 체크하고 기록하여 출력하였다. 

import java.util.*;

class Solution {
    public int[] solution(int[] progresses, int[] speeds) {
        List<Integer> resultList = new ArrayList<>();
        int max = -1000, memory = 0;
        Queue<Integer> q = new ArrayDeque<>();
        
        for(int i = 0 ; i < progresses.length ; i++ ){
            if((100 - progresses[i]) % speeds[i] == 0)
                q.add((100 - progresses[i]) / speeds[i]);
            else
                q.add((100 - progresses[i]) / speeds[i] + 1);
        }
        
        while(!q.isEmpty()){
            if(max >= q.peek()){
                memory += 1;
                q.poll();
            }
            else{
                if(memory != 0){
                    resultList.add(memory);
                    memory = 0;
                }
                max = q.peek();
                memory = 1;
                q.poll();
            }
        }
        
        resultList.add(memory);
        
        int[] answer = new int[resultList.size()];
        for(int i = 0; i < resultList.size(); i++) {
            answer[i] = resultList.get(i);
        }
        
        return answer;
    }
}

'Algorithm & Data Structures > Programers' 카테고리의 다른 글

Lv 2. 프로세스  (0) 2024.06.14
Lv 2. 튜플  (0) 2024.06.13
Lv 2. 1차 캐시  (0) 2024.06.02
Lv 2. pH-index  (0) 2024.05.30
Lv 2. 할인행사  (0) 2024.05.29
'Algorithm & Data Structures/Programers' 카테고리의 다른 글
  • Lv 2. 프로세스
  • Lv 2. 튜플
  • Lv 2. 1차 캐시
  • Lv 2. pH-index
Geisha
Geisha
개발 일기
  • Geisha
    Geisha
    Geisha
  • 전체
    오늘
    어제
    • 분류 전체보기 (326) N
      • Algorithm & Data Structures (246) N
        • BOJ (104) N
        • SWEA (1)
        • Programers (137)
        • Data Structures (3)
      • DB (27) N
        • SQL (21) N
        • RDBMS (2)
      • Java (1)
        • Class (1)
      • Spring (5)
        • Spring MVC (1)
        • Annotations (1)
      • CS (36)
        • 운영체제 (13)
        • 네트워크 (5)
      • Tool (6)
        • Git (5)
        • AWS (1)
      • Project (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    스택
    Dijkstra
    Stack
    programmers
    unionfind
    DynamicProgramming
    BFS
    골드
    SQL
    binarySearch
    PriorityQueue
    전위순회
    다익스트라
    algorithm
    dp
    Union-Find
    투포인터
    백준
    후위순회
    dfs
    Java
    유니온파인드
    경로압축
    프로그래머스
    동적계획법
    알고리즘
    백트래킹
    이분탐색
    baekjoon
    구현
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
Geisha
Lv 2. 기능개발
상단으로

티스토리툴바