250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- joystick
- Animation State Machine
- Hpbar
- 스크롤링
- Prefabs
- 플레이어 방향전환
- 패럴렉스
- raycasting
- 일시정지
- rigidbody
- 플레이어 이동
- 유니티
- 2D슈팅게임
- raycast
- apk
- 오브젝트 풀링
- Blend Type
- LayerMark
- Object Pooling
- Vector3
- Parallax
- 프리팹
- CSharp #자료구조
- Transform
- Object Poling
- Ainimation Blending
- Unity
- Hp바
- rotation
- Scrooling
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.2 귤 고르기 본문
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/138476
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. 정답코드 및 핵심 아이디어, 유의사항
- 크기별로 귤의 개수를 카운트 -> 많은 개수부터 체크
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution
{
public int solution(int k, int[] tangerine)
{
Dictionary<int, int> dict = new Dictionary<int, int>();
int answer = 0;
// 귤 크기에 따라 딕셔너리에 담아 갯수파악
for (int i = 0; i < tangerine.Length; i++)
{
if (!dict.ContainsKey(tangerine[i]))
dict.Add(tangerine[i], 1);
else
dict[tangerine[i]]++;
}
// 딕셔너리의 값을 내림차순 정렬해서 List로 담음
var sortList = dict.OrderByDescending(x => x.Value).ToList();
int sum = 0;
// 가장 많은 수의 귤부터 먼저 넣어서 체크
for (int i = 0; i < sortList.Count; i++)
{
answer++;
sum += sortList[i].Value;
if (sum >= k)
break;
}
return answer;
}
}
728x90
'Programmers - C# > CodingTest Lv.2' 카테고리의 다른 글
[프로그래머스 C#] Lv.2 연속된 부분 수열의 합 (0) | 2023.08.30 |
---|---|
[프로그래머스 C#] Lv.2 연속 부분 수열 합의 개수 (0) | 2023.08.25 |
[프로그래머스 C#] Lv.2 k진수에서 소수 개수 구하기 (0) | 2023.08.25 |
[프로그래머스 C#] Lv.2 호텔 대실 (0) | 2023.08.23 |
[프로그래머스 C#] Lv.2 소수 찾기 (1) | 2023.08.23 |