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
- 유니티
- Unity
- apk
- 일시정지
- rotation
- Object Pooling
- 플레이어 이동
- rigidbody
- Parallax
- Vector3
- Scrooling
- 오브젝트 풀링
- Hpbar
- 2D슈팅게임
- joystick
- Transform
- 스크롤링
- 프리팹
- 패럴렉스
- Object Poling
- Ainimation Blending
- Blend Type
- Prefabs
- CSharp #자료구조
- 플레이어 방향전환
- Animation State Machine
- raycasting
- Hp바
- raycast
- LayerMark
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.3 이중우선순위큐 본문
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/42628
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. 정답코드 및 핵심 아이디어, 유의사항
주어진 조건에 따라 순서대로 값을 추가, 삭제하는 연산을 하여 남아있는 최대 최소 값을 반환하는 문제
직관적인 풀이 - 주석 참조
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution
{
public int[] solution(string[] operations)
{
int[] answer = new int[2] { 0, 0 };
var list = new List<int>();
foreach (string str in operations)
{
string[] strs = str.Split(' ');
// 숫자 추가
if (strs[0] == "I")
{
list.Add(int.Parse(strs[1]));
continue;
}
// 명령 무시 조건
if (list.Count == 0)
continue;
// 최대 값 or 최소 값 삭제
if (strs[1] == "1")
list.Remove(list.Max());
else // strs[1] == "-1"
list.Remove(list.Min());
}
// 값이 남아 있을 경우
if (list.Count > 0)
{
answer[0] = list.Max();
answer[1] = list.Min();
}
return answer;
}
}
728x90
'Programmers - C# > CodingTest Lv.3' 카테고리의 다른 글
[프로그래머스 C#] Lv.3 110 옮기기 (0) | 2024.02.18 |
---|---|
[프로그래머스 C#] Lv.3 순위 (0) | 2024.02.07 |
[프로그래머스 C#] Lv.3 인사고과 (0) | 2024.01.31 |
[프로그래머스 C#] Lv.3 양과 늑대 (1) | 2024.01.29 |
[프로그래머스 C#] Lv.3 입국심사 (0) | 2024.01.26 |