728x90

공부/C# 32

[C#] 코딩테스트에서 쓰는 함수 / 변수

유니티만 하다가 와서 코딩테스트때 유용할 함수 / 변수를 잘 사용하지 못할까봐 나를 위해 모아둔다 using System.Collections.Generic; -> List, Queue 사용 *Dictionary 사용법 익히기 bool[] visited = new bool[크기];array.Length;array.GetLength(0);  ListList list = new List();- list.Contains(a) -> true / false- list.Add(a) QueueQueue queue = new Queue();- queue.Enqueue((0, 0)); - queue.Dequeue();

공부/C# 2025.03.07

[C#] 프로그래머스 백트래킹 - 피로도

https://school.programmers.co.kr/learn/courses/30/lessons/87946 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr1. DFS 위주로 생각2. 방문 확인을 위한 visited, 현재 피로도 값 저장3. public int answer로 표시한 정답값을 자주 업데이트 해주기using System;public class Solution { public int answer = -1; public void DFS(bool[] visited, int[,] dungeons, int currentP, int max){ if (max > answer..

공부/C# 2025.03.07

[C#] 프로그래머스 백트래킹 - 소수 찾기

1. 중복 방지를 위해 List에서 .Contains(num)을 사용 / 중복 방지용으로 visited2. 소수 판별 함수 구현3. 모두 방문해 string으로 +하고 DFS 결과로 int count를 내보내기using System;using System.Collections.Generic;public class Solution { List foundPrimes = new List(); // 중복 방지용 리스트 // 소수 판별 함수 public bool isPrime(int num) { if (num 0) { int num = int.Parse(currentNumber); // 중복되지 않은 숫자이고, 소수라면 카운트 증가 ..

공부/C# 2025.03.07

[C#] 프로그래머스 DFS 연습 - 타겟 넘버

https://school.programmers.co.kr/learn/courses/30/lessons/43165 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr using System;public class Solution { private int answer =0 ; public int solution(int[] numbers, int target) { DFS(0, -1, numbers, target); return answer; } private void DFS(int sum, int index, int[] numbers, int target){..

공부/C# 2025.03.05

[C#] 프로그래머스 DFS 연습 - 네트워크

https://school.programmers.co.kr/learn/courses/30/lessons/43162 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 기존의 작성했던 기본 DFS 구조를 똑같이 사용한 코드https://dani2344.tistory.com/108 [C#] 재귀방식, list를 활용한 DFS 기본 형태using System;using System.Collections.Generic;public class DFSExample { static void DFS(List[] graph, int node, bool[] visited) { //인접 리스트, node 번호, visited ..

공부/C# 2025.03.01
728x90