프로그래머스 2단계 - 기능개발(스택/큐)

프로그래머스 2단계 - 기능개발(스택/큐)

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

Stack 사용

import java.util.*; class Solution { public int[] solution(int[] progresses, int[] speeds) { List countList = new ArrayList<>(); Stack stack = new Stack<>(); List answerList = new ArrayList<>(); //100%까지 걸린 일자 구하기 for(int i=0; i=0; i--){ stack.push(countList.get(i)); } //하나씩 뽑아내기 while(!stack.isEmpty()){ int cnt = 0; int pop = stack.pop(); cnt++; //현재 pop된 값과 다음 값 비교하기 while(!stack.isEmpty() && stack.peek() <= pop){ stack.pop(); cnt++; } //리스트에 기능 갯수 넣기. answerList.add(cnt); } //정답 구하기 int[] answer = new int[answerList.size()]; for(int i=0; i

Stack 미사용

import java.util.*; class Solution { public int[] solution(int[] progresses, int[] speeds) { List countList = new ArrayList<>(); List answerList = new ArrayList<>(); //100%까지 걸린 일자 구하기 for(int i=0; i

from http://sic-dev.tistory.com/97 by ccl(A) rewrite - 2021-09-09 15:01:55