알고리즘 풀이/프로그래머스

[프로그래머스][JAVA] 주식가격 (완전탐색)

배게 2022. 4. 3. 11:12
728x90

2중 for문

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
    public int[] solution(int[] prices) {
        int[] answer = new int[prices.length];
        int len = prices.length;
        
        for(int i=0; i<len; i++){
            for(int j=i+1; j<len; j++){
                answer[i]++;
                if(prices[i]>prices[j]){
                    break;
                }
            }
        }
        return answer;
    }
}
cs