-
-
Save DongguemYoo/d4e372e71b0944e046962886b39427aa to your computer and use it in GitHub Desktop.
코딩테스트 연습(level2) 탑.cs
This file contains 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
//몰랏던것 | |
//Array.Resize하는 방법 | |
//한 20분? >=을 안해서 테스트 케이스에서는 통과해서 찾느라 시간걸림 | |
using System; | |
public class Solution { | |
public int[] solution(int[] heights) { | |
int length = heights.Length; | |
int[] answer = new int[] { 0, }; | |
Array.Resize(ref answer, length); | |
for (int i = 0; i < heights.Length; i++) | |
{ | |
answer[i] = 0; | |
for (int x = i-1; x >= 0; x--) | |
{ | |
if (heights[i] < heights[x]) | |
{ | |
answer[i] = x + 1; | |
break; | |
} | |
} | |
} | |
return answer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment