Skip to content

Instantly share code, notes, and snippets.

@DongguemYoo
Created May 20, 2020 06:38
Show Gist options
  • Save DongguemYoo/45155b6cecae3b3d3cdd721c708980cd to your computer and use it in GitHub Desktop.
Save DongguemYoo/45155b6cecae3b3d3cdd721c708980cd to your computer and use it in GitHub Desktop.
코딩테스트 연습 > 스택/큐 > 주식가격.cs
//간단하게 풀었지만 스택/큐를 사용하지 않았다..
//이전에 복잡하게 풀어서 안풀리던거를 오렌만에 봐서 다시 생각해서 풀어서 10분정도 걸린듯
//운이 좋았다 for문에서 체크하니까 정답이랑 time차이가 1씩 났음
//그래서 time에 -1을 해주니까 그냥 풀림;;
public int[] solution(int[] prices)
{
int[] answer = new int[prices.Length];
int count = 0;
int value = 0;
int time = 0;
while (count != prices.Length)
{
value = prices[count];
time = 0;
for (int i = count; i < prices.Length; i++)
{
time++;
if (value > pricess[i])
break;
}
time -= 1;
answer[count] = time;
count++;
}
return answer;
}
//다른사람이 푼 방식
//다들 비슷하게 풀어서 딱히 참고할게 없는듯..간단한
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment