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
- 오브젝트 풀링
- Vector3
- Scrooling
- Hp바
- 유니티
- Parallax
- Transform
- Prefabs
- rigidbody
- Unity
- 일시정지
- 패럴렉스
- Hpbar
- Ainimation Blending
- 프리팹
- apk
- rotation
- Object Poling
- CSharp #자료구조
- LayerMark
- 플레이어 이동
- Animation State Machine
- joystick
- raycasting
- 스크롤링
- 2D슈팅게임
- raycast
- Object Pooling
- 플레이어 방향전환
- Blend Type
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.2 모음사전 본문
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/84512
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. 정답코드 및 핵심 아이디어, 유의사항
주어진 조건에 따른 사전에서 찾는 단어가 몇번째로 있는지 찾는 문제
- 조건에 따라 알파벳으로 만들 수 있는 모든 단어를 list에 저장 ( DFS 이용 )
- 저장한 list를 오름차순 정렬하여 주어진 문제처럼 순서대로 배치
ex) list[0] : A, list[1] : AA, list[2] : AAA ....
DFS 알고리즘
https://godgjwnsgur7.tistory.com/47
[Algorithm C#] BFS, DFS ( + Back Tracking )
1. BFS(Breadth First Search) - 너비 우선 탐색 최단 경로, 임의의 경로를 찾고 싶을 때, 등에 사용 - 큐(FIFO) 사용 // 큐를 이용 public void BFS(int index) { Node root = nodes[index]; Queue queue = new Queue(); queue.Enqueue(root
godgjwnsgur7.tistory.com
주석 참조
using System;
using System.Collections.Generic;
public class Solution
{
public int solution(string word)
{
var list = new List<string>(); // 알파벳 사전 리스트
var charArray = new Char[5] { 'A', 'E', 'I', 'O', 'U' };
// 각 자릿수에 대한 모든 경우의 수를 list에 넣기
for (int i = 1; i <= charArray.Length; i++)
DFS("", 0, i, charArray, list);
// 오름차순 정렬
list.Sort();
return list.FindIndex(s => s == word) + 1;
}
public void DFS(string str, int currLength, int maxLength, char[] charArray, List<string> list)
{
// 목표 자리 수에 도달
if (currLength == maxLength)
{
list.Add(str);
return;
}
for (int i = 0; i < charArray.Length; i++)
DFS(str + charArray[i], currLength + 1, maxLength, charArray, list);
}
}
728x90
'Programmers - C# > CodingTest Lv.2' 카테고리의 다른 글
[프로그래머스 C#] Lv.2 당구 연습 (0) | 2024.02.26 |
---|---|
[프로그래머스 C#] Lv.2 이모티콘 할인행사 (0) | 2024.02.16 |
[프로그래머스 C#] Lv.2 주차 요금 계산 (0) | 2024.02.08 |
[프로그래머스 C#] Lv.2 테이블 해시 함수 (0) | 2024.02.06 |
[프로그래머스 C#] Lv.2 쿼드압축 후 개수 세기 (0) | 2024.01.27 |