GaGe

[프로그래머스] 탑 - java 본문

알고리즘/[2020] 프로그래머스

[프로그래머스] 탑 - java

Sorrel 2020. 4. 12. 14:25
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; 
    } 
}
Comments