Created
January 9, 2020 01:32
-
-
Save dalcon10028/37900a2c0d2a0f7ba3bc833e0294feee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public int[] solution(int[] heights) { | |
| int []answer = new int[heights.length]; // 초기화, int는 기본값 0 | |
| for(int i=heights.length-1; i>=0; i--){ // 맨 뒤 요소부터 확인합니다. | |
| int tower = heights[i]; // 맨 뒤 요소 넣기 | |
| for(int j=i-1; j>=0 ;j--){ // 맨 뒤 요소의 바로 앞 요소부터 맨 앞 요소까지 확인합니다. | |
| if (tower < heights[j]) { // 앞에 요소중 맨 뒤 요소보다 큰 게 있으면 체크 | |
| answer[i] = j+1; // 1부터 세기 때문에 인덱스 + 1 | |
| break; | |
| } | |
| } | |
| } | |
| return answer; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment