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 |
Tags
- 수학숙제
- 코딩테스트
- 17070번
- 백준 2870번
- 백준
- 프로그래머스
- 백준 c++ 2468번
- 플레이어 이동
- Lv2
- 백준 17070번
- 유니티
- 2870번 수학숙제
- c++
- 2468 c++
- dfs
- C#
- 백준 1103번 c++
- 백준 c++ 2870번
- 2870번 수학숙제 c++
- 백준 1103번
- 백준 1103번 게임
- Algorithm
- Lv.3
- 오브젝트 풀링
- 백준 17070번 c++
- Beakjoon
- Unity
- 2870번 c++
- 코테
- 2870번
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.3 이중우선순위큐 본문
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;
}
}
'CodingTest > Programmers 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 입국심사 (0) | 2024.01.26 |
[프로그래머스 C#] Lv.3 다단계 칫솔 판매 (1) | 2024.01.25 |