Skip to content

Instantly share code, notes, and snippets.

@DongguemYoo
Created May 11, 2020 06:44
Show Gist options
  • Save DongguemYoo/b731c5cc293c5d0cabf759d23b98b18d to your computer and use it in GitHub Desktop.
Save DongguemYoo/b731c5cc293c5d0cabf759d23b98b18d to your computer and use it in GitHub Desktop.
코딩테스트 연습 스택/큐 기능개발.cs
//일단...스택이나 큐를 쓰지않았다 ㅠㅠ..
using System;
public class Solution {
public int[] solution(int[] progresses, int[] speeds)
{
int[] answer = new int[] { };
int[] ret = new int[] { };
int endDay;
Array.Resize(ref answer, progresses.Length);
//개발에 걸리는 날짜 계산
for (int i = 0; i < progresses.Length; i++)
{
endDay = 0;
while (progresses[i] < 100)
{
endDay++;
progresses[i] += speeds[i];
}
answer[i] = endDay;
}
//이전날 보다 적은 날이 걸렸다면 이전날과 같은날에 배포 되므로 이전날짜로 변경
for (int i = 0; i < answer.Length - 1; i++)
{
if (answer[i] > answer[i + 1])
answer[i + 1] = answer[i];
}
Array.Resize(ref ret, 1);
int idx = 0;
int firstValue = answer[0];
//같은 날짜인 것끼리 카운트 해주고 다르다면 배열 증가
foreach (var x in answer)
{
if (firstValue != x)
{
Array.Resize(ref ret, ret.Length + 1);
firstValue = x;
idx++;
ret[idx]++;
continue;
}
ret[idx]++;
}
return ret;
}
}
//다른사람들 코드도 비슷비슷한듯...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment