롤케이크 자르기 문제
내 코드
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public int solution(int[] topping) {
int answer = 0;
Stack<int> stack = new Stack<int>(topping);
var dic = topping.GroupBy(x => x).ToDictionary(x=>x.Key,x=>x.Count());
HashSet<int> hashSet = new HashSet<int>();
while(stack.Count > 0)
{
int n = stack.Pop();
hashSet.Add(n);
if (dic[n] == 1)
dic.Remove(n);
else
dic[n]--;
if(dic.Count() == hashSet.Count)
answer++;
}
return answer;
}
}
728x90
반응형
'코딩테스트_c# > 프로그래머스' 카테고리의 다른 글
프로그래머스 ) 의상 Level.2_C# (0) | 2024.11.27 |
---|---|
프로그래머스 ) 두 큐 합 같게 만들기 Level.2_ C# (0) | 2024.11.12 |
프로그래머스 ) 코딩테스트 연습 - 성격 유형 검사하기 Level.1_C# (0) | 2024.11.11 |
프로그래머스 ) 코딩테스트 연습 - 호텔 대실 Level.2_C# (0) | 2024.07.26 |
프로그래머스 ) 코딩테스트 연습 - 신고결과 받기 Level.1_C# (0) | 2024.07.19 |