프로그래머스 모음 사전 문제풀이 C#

안또니오·2022년 11월 16일
0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Solution s = new Solution();
            
            Console.WriteLine(s.solution("A"));
        }
    }
    public class Solution
    {
        public string[] chars = { "A", "E", "I", "O", "U" };

        int count = 0;
        int answer = 0;
        public int solution(string word)
        {

            dfs("", word);
            return answer;
        }
        public void dfs(string now, string target)
        {
            if (now.Equals(target))
            {
                answer = count;
                return;
            }
            if (now.Length == 5) return;
            for(int i = 0; i <chars.Length; i++)
            {
                count++;
                string word = now + chars[i];
                dfs(word,target);
            }
        }
    }
}
profile
2020. 11월 공부시작.

0개의 댓글