본문 바로가기

Algorithm/Stack, Queue

[프로그래머스] 주식가격 [JAVA]

import java.util.LinkedList;
import java.util.Queue;
class Solution {
    public int[] solution(int[] prices) {
        Queue<Integer> que=new LinkedList<>(Arrays.asList(prices));
        int[] answer = new int[prices.length];
        
		int flag=0;
        
		while(!que.isEmpty()) {
        	int tmp=que.poll();
        
        	for(int i=flag;i<prices.length;i++) {
        		if(prices[i]>=tmp) {
        
        			if(i==prices.length-1) {
        				answer[flag]=i-flag;
        				break;
        			}
        			else {
        				continue;
        			}
        			
        		}
        		else {
        			
        			answer[flag]=i-flag;
        			break;
        		}
        	}
        	flag++;
        
        }
		
        return answer;
    }
}