요르딩딩

[프로그래머스] 스택/큐 - 기능개발 본문

[코딩테스트]/문제풀이

[프로그래머스] 스택/큐 - 기능개발

요르딩딩 2021. 6. 4. 14:46
728x90
반응형
import java.util.*;
import java.util.HashMap;
import org.junit.Test;
import java.util.*;

class Solution {
    public int[] solution(int[] progresses, int[] speeds) {
    			List<Integer> modList = new ArrayList<Integer>();

		for (int i = 0; i < progresses.length; i++) {
			int num = (int) Math.ceil((double)(100 - progresses[i]) / speeds[i]);
			modList.add(num);
		}

		int max=0;
		int count=1;
		List<Integer> resultList = new ArrayList<Integer>();
		for (int i = 0; i < modList.size(); i++) {
			if(i==0) {
				max = modList.get(0);
				continue;
			}
			
			if(max < modList.get(i)) {
				resultList.add(count);
				max = modList.get(i);
				count=1;
			}else {
				count++;
			}
			
			if(i == modList.size()-1) {
				resultList.add(count);
			}
		}
		//결과세팅
		int answer[] = new int[resultList.size()];
		for(int i=0; i<resultList.size(); i++) {
			answer[i] = resultList.get(i);
			}
		
		return answer;
    }
}
728x90
반응형
Comments