코딩 테스트 맨텀 2023. 5. 6. 11:34
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/12987 나의 코드 public int solution(int[] A, int[] B) { int answer = 0; var listB = B.OrderByDescending(o => o).ToList(); foreach(int cur in A.OrderByDescending(o => o)) { if(cur >= listB[answer]) continue; // B의 현재 최대값이 이길 수 있을 때 까지 넘김 ++answer; } return answer; } 비기거나 지는 경우 점수가 변하지 않는다 -> 이기는 경우만 생각하면 된다. 출전 순서에 따라서 점수가..
코딩 테스트 맨텀 2023. 5. 5. 11:18
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/43163 나의 풀이 public int solution(string begin, string target, string[] words) { if(!words.Contains(target)) return 0; int answer = int.MaxValue; bool[] visit = new bool[words.Length]; DFS(0, begin, target, words, visit, ref answer); return answer == int.MaxValue ? 0 : answer; } void DFS(int n, string cur, string target..
코딩 테스트 맨텀 2023. 5. 4. 22:22
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/42579 나의 풀이 public int[] solution(string[] genres, int[] plays) { var zipList = Enumerable.Range(0, genres.Length) .Select(s => new{ index = s, genre = genres[s], play = plays[s]}) .ToList(); List genreRank = zipList.GroupBy(g => g.genre) .Select(s => new{ genre = s.Key, sum = s.Sum(t => t.play)} ) .OrderByDescending(..
코딩 테스트 맨텀 2023. 5. 3. 21:39
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/12927 나의 풀이 public long solution(int n, int[] works) { Array.Sort(works); for(int i = 0; i 0 && works[maxIndex - 1] >= works[maxIndex]) --maxIndex; if(works[maxIndex] == 0) return 0; --works[maxIndex]; } retu..
코딩 테스트 맨텀 2023. 5. 2. 22:33
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/43162 나의 풀이 public int solution(int n, int[,] computers) { int answer = 0; var open = new Stack(); var close = new HashSet(); for(int i = 0; i 0) { int popIndex = open.Pop(); for(int k = 0; k < n; ++k) { if(close.Contains(k)) contin..
코딩 테스트 맨텀 2023. 5. 1. 19:21
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/42628 나의 풀이 public class Solution { public int[] solution(string[] operations) { var queue = new MyQueue(); foreach(string str in operations) { if(str == "D 1") { queue.DeleteMax(); } else if(str == "D -1") { queue.DeleteMin(); } else { int n = int.Parse(str.Split()[1]); queue.Add(n); } } return queue.Count > 0 ? new ..