been_dev
been_archive
been_dev
전체 방문자
오늘
어제
  • 분류 전체보기 (34)
    • f-lab (3)
    • project (2)
    • solve (29)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 스택
  • f-lab 2개월 후기
  • f-lab
  • Downloading from external resources is disabled
  • 에프랩
  • 탐욕법
  • MYSQL
  • 숫자의표현
  • f-lab 1개월 후기
  • 실행창 작음
  • 프로그래머스
  • 그리디
  • 문자열
  • JWT
  • Lombok
  • 에프랩 2개월 후기
  • 자바
  • 해시
  • 이진변환반복하기
  • 버튼미노출
  • 완전탐색
  • 큐
  • 후기
  • 백준
  • 코딩테스트
  • jadencase만들기
  • specify location
  • 에프랩 1개월 후기
  • 자바 백엔드
  • Eclipse

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
been_dev

been_archive

solve

[프로그래머스/큐] Lv2. 프로세스 (자바)

2024. 1. 12. 13:40

클래스를 정의하여 구현

 

참고 : 개발자로 취직하기 유튜브

import java.util.*;

class Solution {
    public int solution(int[] priorities, int location) {
        // 1. Queue  를 만들기
        List<PrintJob> printer = new ArrayList<PrintJob>();
        for(int i = 0; i < priorities.length; i++){
            printer.add(new PrintJob(i, priorities[i]));
        }
        int turn = 0;
        while(!printer.isEmpty()) {
            // 2. 0 번을 꺼내서 max priority 가 아니면 끝에 넣는다.
            PrintJob job = printer.remove(0);
            // 현재 job 보다 우선 순위가 높은 job 이 있으면
            if(printer.stream().anyMatch(otherJob -> job.priority < otherJob.priority)) {
               printer.add(job); // 다시 넣어줌 
            } 
            // 3. max priority 이면 내가 찾는 job 이 맞는지 확인한다.
            else {
                turn++;
                // 구하려고 한 위치의 job 이 맞는지
                if(location == job.location) {
                    break;
                }
            }
        }
        
        return turn;
    }
    
    class PrintJob {
        int priority;
        int location;
        
        PrintJob(int location, int priority) {
            this.location = location;
            this.priority = priority;
        }
    }
}

 

'solve' 카테고리의 다른 글

[프로그래머스/BFS] Lv2. 게임 맵 최단 거리 (자바)  (0) 2024.01.13
[프로그래머스/큐] Lv2. 기능 개발 (자바)  (0) 2024.01.12
[백준 1764/해시] 실버4/듣보잡 (자바)  (0) 2024.01.11
[프로그래머스/해시] Lv1. 신고 결과 받기(자바)  (0) 2024.01.11
[프로그래머스/해시] Lv2. 순위 검색 (자바)  (1) 2024.01.11
    'solve' 카테고리의 다른 글
    • [프로그래머스/BFS] Lv2. 게임 맵 최단 거리 (자바)
    • [프로그래머스/큐] Lv2. 기능 개발 (자바)
    • [백준 1764/해시] 실버4/듣보잡 (자바)
    • [프로그래머스/해시] Lv1. 신고 결과 받기(자바)
    been_dev
    been_dev

    티스토리툴바