관리 메뉴

MOMONOTE

(JAVA) 프로그래머스 주식가격 (스택/큐) 본문

알고리즘, 코딩테스트/(JAVA)프로그래머스

(JAVA) 프로그래머스 주식가격 (스택/큐)

momo0503 2021. 4. 6. 15:52

class Solution {
    public int[] solution(int[] prices) {
        int[] answer = new int[prices.length];
        
        int count=0;
        
        for(int i=0;i<prices.length;i++){
          
            for(int j=i+1;j<prices.length;j++){
                count++;
                if(prices[i]>prices[j]){
                    break;
                }
            }
            answer[i]=count;
            count=0;
        }
        
        
        return answer;
    }
}

- prices 배열 의 요소들을 비교해가며 count를 증가시키고 

- 결과를 answer 배열에 넣어 리턴한다. 

- 스택/큐 알고리즘 분야인데 굳이 쓰지않고도 잘 풀린다. 

 

 

Comments