Cute Dog Bopping Head
본문 바로가기

스택3

[프로그래머스] 다리를 지나는 트럭 - Stack, Queue (Java) import java.util.LinkedList; import java.util.Queue; class Solution { public int solution(int bridge_length, int weight, int[] truck_weights) { //다리 길이만큼 0을 가지는 큐 생성 Queue acrossQ = new LinkedList(); for(int i=0;i0){ acrossWeight -= acrossQ.peek(); acrossQ.poll(); second++; } return second; } } 다리 위 무게 - 큐 가장 앞의 무게 + 그 다음에 올 트럭 무게 !!!!!!!!!!! 계속 다리 위 무게 + 그 다음 트럭 무게 와 weight를 비교했다. 그 과정에서, 큐 가장 .. 2021. 8. 21.
[프로그래머스] 프린터 - Stack,Queue (Java) import java.util.*; class Solution { public int solution(int[] priorities, int location) { int answer = 1; //큐와 arraylist에 중요도 추가. Queue queue = new LinkedList(); for (int i = 0; i < priorities.length; i++){ queue.add(priorities[i]); } //max 값 찾아서 poll하는 작업 반복, 목표 작업에 도달시 return int maxIndex = 0; int targetIndex = location; while(!queue.isEmpty()){ ArrayList queueArr = new ArrayList(queue); maxI.. 2021. 8. 16.
[프로그래머스] 기능개발 - Stack,Queue (Java) import java.util.*; class Solution { public int[] solution(int[] progresses, int[] speeds) { Queue queue = new LinkedList(); //각 작업 당 필요한 날의 수를 큐에 저장. for(int i=0;i 0) //나머지 존재 시 1일 추가. needDay += 1; queue.offer(needDay);//스택은 push & pop, 큐는 offer & poll } //현재 poll되는 날보다 더 긴 기간이 필요한 작업이 나올때까지 poll. int dayPassed = queue.poll(); ArrayList result = new ArrayList(); int arrayListIndex = 0; result... 2021. 8. 16.