본문 바로가기

카테고리 없음

프로그래머스>스택/큐>주식가격

import java.util.Arrays;

class Solution {
    public int[] solution(int[] prices) {
        
        int[] answer = new int [prices.length];
        
        for(int i=0; i<prices.length; i++)
        { 
            for(int j= i+1; j<prices.length; j++)
            {
                if(prices[i]>prices[j])
                {
                    answer[i]= j-i;
                    break;
                }
                /*
                 if(j == answer.length -1)
                    answer [i] = j-i;
         */
        }
        }
        System.out.println(Arrays.toString(answer));
        return answer;
    }
}