코딩 테스트 맨텀 2023. 3. 19. 17:11
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/118667 1차시도 public int solution(int[] queue1, int[] queue2) { long sum1 = queue1.Sum(); long sum2 = queue2.Sum(); if(sum1 == sum2) return 0; // 이미 같다면 수행 필요 없음 long sum = sum1 + sum2; if(sum % 2 == 1) return -1; // 홀수는 같은 값으로 나눌 수 없음 var q1 = new Queue(queue1); var q2 = new Queue(queue2); int maxTryCount = queue1.Leng..
코딩 테스트 맨텀 2023. 3. 18. 12:28
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/131704 나의 풀이 public int solution(int[] order) // 택배 기사가 원하는 순서 { int orderIndex = 0; // 택배 기사가 원하는 순서의 배열 인덱스 var stack = new Stack(); // 보조 벨트 for(int i = 0; i 0 && sta..
코딩 테스트 맨텀 2023. 3. 17. 13:39
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/132265 1차시도 public int solution(int[] topping) { int answer = 0; var stack = new Stack(topping); var rightSet = new HashSet(); while(stack.Count > 1) { int pop = stack.Pop(); rightSet.Add(pop); if(stack.Distinct().Count() == rightSet.Count) ++answer; } return answer; } 모든 원소를 stack에 담아두고 하나씩 꺼내가면서 hashSet에 넣어서 중복제거하고 ..
코딩 테스트 맨텀 2023. 3. 16. 19:13
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/154539 나의 코드 using System; using System.Collections.Generic; public class Solution { public int[] solution(int[] numbers) { // 스택에 넣으면서 top보다 큰 수가 온 경우 pop을 반복하고, 현재 숫자를 pop된 index에 넣어준다. int[] answer = new int[numbers.Length]; var stack = new Stack(); for(int i = 0; i 0 &&..
코딩 테스트 맨텀 2023. 3. 16. 19:05
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/154538 나의 코드 using System; using System.Linq; using System.Collections.Generic; public class Solution { public int solution(int x, int y, int n) { var open = new HashSet(); var openOther = new HashSet(); var close = new HashSet(); int count = 0; open.Add(x); while(open.Count > 0) { if(open.Contains(y)) return count; +..
코딩 테스트 맨텀 2023. 3. 10. 12:35
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/42839 나의 풀이 using System; using System.Linq; using System.Collections.Generic; public class Solution { public int solution(string numbers) { var hashSet = new HashSet(); for(int i = 1; i