목록알고리즘 (35)
알맹이방
import java.util.Queue; import java.util.LinkedList; class Solution { class Truck { //트럭 각각의 무게와 입장시간을 기억하는 구조체(이 세트로 큐에 들어감) int weight; int start; Truck(int weight, int start){ this.weight = weight; this.start = start; } } public int solution(int bridge_length, int weight, int[] truck_weights) { Queue a = new LinkedList(); //Truck구조체로 설정 Queue b = new LinkedList(); for(int i = 0 ; i < truck_we..
class Solution { public int[] solution(int[] prices) { int[] answer = new int [prices.length]; for(int i=0; i
class Solution { public int[] solution(int[] heights) { int[] answer = new int [heights.length]; for(int i = heights.length-1 ; i>=0 ; i--){ for(int j = i ; j>=0 ; j--){ if(heights[j]>heights[i]){ answer[i]=j+1; break; } if(j==0){ answer[i]=0; break; } } } return answer; } }