<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>hoony-code.log</title>
        <link>https://velog.io/</link>
        <description>배우는 개발자가 되고 싶습니다.</description>
        <lastBuildDate>Thu, 12 May 2022 08:17:48 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>hoony-code.log</title>
            <url>https://images.velog.io/images/hoony-code/profile/1d892ac1-0ec4-4e5c-a0a0-e2916bb0a4a9/social.jpeg</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. hoony-code.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/hoony-code" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[[백준] 14621 나만 안되는 연애 JAVA]]></title>
            <link>https://velog.io/@hoony-code/%EB%B0%B1%EC%A4%80-14621-%EB%82%98%EB%A7%8C-%EC%95%88%EB%90%98%EB%8A%94-%EC%97%B0%EC%95%A0-JAVA</link>
            <guid>https://velog.io/@hoony-code/%EB%B0%B1%EC%A4%80-14621-%EB%82%98%EB%A7%8C-%EC%95%88%EB%90%98%EB%8A%94-%EC%97%B0%EC%95%A0-JAVA</guid>
            <pubDate>Thu, 12 May 2022 08:17:48 GMT</pubDate>
            <description><![CDATA[<h2 id="문제">문제</h2>
<p>깽미는 24살 모태솔로이다. 깽미는 대마법사가 될 순 없다며 자신의 프로그래밍 능력을 이용하여 미팅 어플리케이션을 만들기로 결심했다. 미팅 앱은 대학생을 타겟으로 만들어졌으며 대학교간의 도로 데이터를 수집하여 만들었다.</p>
<p>이 앱은 사용자들을 위해 사심 경로를 제공한다. 이 경로는 3가지 특징을 가지고 있다.</p>
<ol>
<li>사심 경로는 사용자들의 사심을 만족시키기 위해 남초 대학교와 여초 대학교들을 연결하는 도로로만 이루어져 있다.</li>
<li>사용자들이 다양한 사람과 미팅할 수 있도록 어떤 대학교에서든 모든 대학교로 이동이 가능한 경로이다.</li>
<li>시간을 낭비하지 않고 미팅할 수 있도록 이 경로의 길이는 최단 거리가 되어야 한다.</li>
</ol>
<p>만약 도로 데이터가 만약 왼쪽의 그림과 같다면, 오른쪽 그림의 보라색 선과 같이 경로를 구성하면 위의 3가지 조건을 만족하는 경로를 만들 수 있다.</p>
<p><img src="https://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/14621/1.png" alt="img"></p>
<p>이때, 주어지는 거리 데이터를 이용하여 사심 경로의 길이를 구해보자.</p>
<h2 id="입력">입력</h2>
<p>입력의 첫째 줄에 학교의 수 N와 학교를 연결하는 도로의 개수 M이 주어진다. (2 ≤ N ≤ 1,000) (1 ≤ M ≤ 10,000)</p>
<p>둘째 줄에 각 학교가 남초 대학교라면 M, 여초 대학교라면 W이 주어진다.</p>
<p>다음 M개의 줄에 u v d가 주어지며 u학교와 v학교가 연결되어 있으며 이 거리는 d임을 나타낸다. (1 ≤ u, v ≤ N) , (1 ≤ d ≤ 1,000)</p>
<h2 id="출력">출력</h2>
<p>깽미가 만든 앱의 경로 길이를 출력한다. (모든 학교를 연결하는 경로가 없을 경우 -1을 출력한다.)</p>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>모든 경로를 만든 것을 구하는 최소 스패닝 트리를 구하는 문제라고 생각했다</li>
<li>MST를 구현하는 알고리즘 중 크루스칼 알고리즘을 사용해서 문제를 해결하자고 생각했다.</li>
</ul>
<ol>
<li>먼저 주어진 입력값을 받는다</li>
<li>조건중 동일한 성별이면 LIst에 처음부터 넣지 않는다</li>
</ol>
<pre><code class="language-java">int u, v, d;
for (int i = 0; i &lt; M; i++) {
    in = br.readLine().split(&quot; &quot;);
    u = Integer.parseInt(in[0]);
    v = Integer.parseInt(in[1]);
    d = Integer.parseInt(in[2]);

    // 동일한 성별이면 리스트에서 제외한다
    if (arr[u] == arr[v]) continue;

    edgeList.add(new Edge(u, v, d));
}</code></pre>
<ol start="3">
<li>가중치 크기 순으로 정렬한다</li>
</ol>
<pre><code class="language-java">Collections.sort(edgeList, (o1, o2) -&gt; Integer.compare(o1.d, o2.d));</code></pre>
<ol start="4">
<li>부모를 초기화하고 N-1 까지 연결되면 답을 출력한다</li>
</ol>
<pre><code class="language-java">initParents();

int nodeCnt = 0;
int answer = 0;
for (Edge temp : edgeList) {

    if (union(temp.u, temp.v)) {
        nodeCnt++;
        answer += temp.d;
        if (nodeCnt == N - 1) {
            System.out.println(answer);
            return;
        }
    }
}

System.out.println(-1);</code></pre>
<h2 id="풀이-코드">풀이 코드</h2>
<pre><code class="language-java">package BOJ;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class BOJ_나만안되는연애_HoonyCode {

    static int N, M;
    static char[] arr;
    static int[] parents;

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


        // 학교의 수 N 과 도로의 개수 M;
        String[] in = br.readLine().split(&quot; &quot;);
        N = Integer.parseInt(in[0]);
        M = Integer.parseInt(in[1]);
        parents = new int[N + 1];

        arr = new char[N + 1];
        in = br.readLine().split(&quot; &quot;);
        // 남 녀 구별 M // W;
        for (int i = 1; i &lt;= N; i++) {
            arr[i] = in[i - 1].charAt(0);
        }

        List&lt;Edge&gt; edgeList = new ArrayList&lt;&gt;();

        int u, v, d;
        for (int i = 0; i &lt; M; i++) {
            in = br.readLine().split(&quot; &quot;);
            u = Integer.parseInt(in[0]);
            v = Integer.parseInt(in[1]);
            d = Integer.parseInt(in[2]);

            if (arr[u] == arr[v]) continue;

            edgeList.add(new Edge(u, v, d));
        }

        Collections.sort(edgeList, (o1, o2) -&gt; Integer.compare(o1.d, o2.d));

        initParents();

        int nodeCnt = 0;
        int answer = 0;
        for (Edge temp : edgeList) {

            if (union(temp.u, temp.v)) {
                nodeCnt++;
                answer += temp.d;
                if (nodeCnt == N - 1) {
                    System.out.println(answer);
                    return;
                }
            }
        }

        System.out.println(-1);
    }

    static boolean union(int x, int y) {
        x = find(x);
        y = find(y);

        if (x == y) {
            return false;
        } else {
            parents[y] = x;
            return true;
        }
    }

    static void initParents() {
        for (int i = 1; i &lt;= N; i++) {
            parents[i] = i;
        }
    }

    static int find(int x) {

        if (x != parents[x]) {
            return parents[x] = find(parents[x]);
        }
        return parents[x];
    }

    static class Edge {
        int u, v, d;

        public Edge(int u, int v, int d) {
            this.u = u;
            this.v = v;
            this.d = d;
        }
    }

}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[백준] 11657 타임머신 JAVA]]></title>
            <link>https://velog.io/@hoony-code/%EB%B0%B1%EC%A4%80-11657-%ED%83%80%EC%9E%84%EB%A8%B8%EC%8B%A0-JAVA</link>
            <guid>https://velog.io/@hoony-code/%EB%B0%B1%EC%A4%80-11657-%ED%83%80%EC%9E%84%EB%A8%B8%EC%8B%A0-JAVA</guid>
            <pubDate>Thu, 12 May 2022 07:44:48 GMT</pubDate>
            <description><![CDATA[<h2 id="문제">문제</h2>
<p>N개의 도시가 있다. 그리고 한 도시에서 출발하여 다른 도시에 도착하는 버스가 M개 있다. 각 버스는 A, B, C로 나타낼 수 있는데, A는 시작도시, B는 도착도시, C는 버스를 타고 이동하는데 걸리는 시간이다. 시간 C가 양수가 아닌 경우가 있다. C = 0인 경우는 순간 이동을 하는 경우, C &lt; 0인 경우는 타임머신으로 시간을 되돌아가는 경우이다.</p>
<p>1번 도시에서 출발해서 나머지 도시로 가는 가장 빠른 시간을 구하는 프로그램을 작성하시오.</p>
<h2 id="입력">입력</h2>
<p>첫째 줄에 도시의 개수 N (1 ≤ N ≤ 500), 버스 노선의 개수 M (1 ≤ M ≤ 6,000)이 주어진다. 둘째 줄부터 M개의 줄에는 버스 노선의 정보 A, B, C (1 ≤ A, B ≤ N, -10,000 ≤ C ≤ 10,000)가 주어진다. </p>
<h2 id="출력">출력</h2>
<p>만약 1번 도시에서 출발해 어떤 도시로 가는 과정에서 시간을 무한히 오래 전으로 되돌릴 수 있다면 첫째 줄에 -1을 출력한다. 그렇지 않다면 N-1개 줄에 걸쳐 각 줄에 1번 도시에서 출발해 2번 도시, 3번 도시, ..., N번 도시로 가는 가장 빠른 시간을 순서대로 출력한다. 만약 해당 도시로 가는 경로가 없다면 대신 -1을 출력한다.</p>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>음의 가중치 값이 있는 문제는 벨만포드 알고리즘을 사용해서 풀면 된다고 생각했다</li>
</ul>
<ol>
<li>Edge class 를 만들어서 다음 노드와 가중치를 adjList에 넣는다</li>
</ol>
<pre><code class="language-java">for (int i = 0; i &lt; M; i++) {
    input = br.readLine().split(&quot; &quot;);
    from = Integer.parseInt(input[0]);
    to = Integer.parseInt(input[1]);
    weight = Integer.parseInt(input[2]);
    adjlist[from].add(new Edge(to, weight));
}</code></pre>
<ol start="2">
<li>벨만포드 알고리즘을 사용해서 N번 돌았을 때 값이 변경된다면 사이클이 존재한다는 뜻으로 -1값을 출력한다</li>
</ol>
<pre><code class="language-java">long[] dist = new long[N + 1];
Arrays.fill(dist, Integer.MAX_VALUE);

dist[1] = 0;
for (int i = 1; i &lt;= N; i++) {
    for (int j = 1; j &lt;= N; j++) {
        for (Edge edge : adjlist[j]) {
            if (dist[j] != Integer.MAX_VALUE &amp;&amp; dist[edge.to] &gt; dist[j] + edge.weight) {
                dist[edge.to] = dist[j] + edge.weight;
                if (i == N) {
                    System.out.println(-1);
                    return;
                }
            }
        }
    }
}</code></pre>
<ol start="3">
<li>사이클이 존재하지 않는다면  갈수 없는 지역은 -1로 갈 수 있는 곳은 최소값을 출력한다</li>
</ol>
<pre><code class="language-java">StringBuilder sb = new StringBuilder();
for (int i = 2; i &lt;= N; i++) {
    if (dist[i] == Integer.MAX_VALUE)
        sb.append(-1).append(&#39;\n&#39;);
    else
        sb.append(dist[i]).append(&#39;\n&#39;);
}
System.out.print(sb.toString());</code></pre>
<h2 id="코드">코드</h2>
<pre><code class="language-java">import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {

    static int N, M;
    static List&lt;Edge&gt;[] adjlist;


    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(&quot; &quot;);
        N = Integer.parseInt(input[0]);
        M = Integer.parseInt(input[1]);

        adjlist = new List[N + 1];
        for (int i = 1; i &lt;= N; i++) {
            adjlist[i] = new ArrayList&lt;&gt;();
        }

        int from, to, weight;
        for (int i = 0; i &lt; M; i++) {
            input = br.readLine().split(&quot; &quot;);
            from = Integer.parseInt(input[0]);
            to = Integer.parseInt(input[1]);
            weight = Integer.parseInt(input[2]);
            adjlist[from].add(new Edge(to, weight));
        }

        bellmanford();

    }

    private static void bellmanford() {
        long[] dist = new long[N + 1];
        Arrays.fill(dist, Integer.MAX_VALUE);

        dist[1] = 0;
        for (int i = 1; i &lt;= N; i++) {
            for (int j = 1; j &lt;= N; j++) {
                for (Edge edge : adjlist[j]) {
                    if (dist[j] != Integer.MAX_VALUE &amp;&amp; dist[edge.to] &gt; dist[j] + edge.weight) {
                        dist[edge.to] = dist[j] + edge.weight;
                        if (i == N) {
                            System.out.println(-1);
                            return;
                        }
                    }
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 2; i &lt;= N; i++) {
            if (dist[i] == Integer.MAX_VALUE)
                sb.append(-1).append(&#39;\n&#39;);
            else
                sb.append(dist[i]).append(&#39;\n&#39;);
        }
        System.out.print(sb.toString());

    }

    static class Edge {
        int to;
        int weight;

        public Edge(int to, int weight) {
            this.to = to;
            this.weight = weight;
        }
    }
}
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[백준] 1719 택배 JAVA]]></title>
            <link>https://velog.io/@hoony-code/%EB%B0%B1%EC%A4%80-1719-%ED%83%9D%EB%B0%B0-JAVA</link>
            <guid>https://velog.io/@hoony-code/%EB%B0%B1%EC%A4%80-1719-%ED%83%9D%EB%B0%B0-JAVA</guid>
            <pubDate>Thu, 12 May 2022 07:37:37 GMT</pubDate>
            <description><![CDATA[<h2 id="문제">문제</h2>
<p>명우기업은 2008년부터 택배 사업을 새로이 시작하기로 하였다. 우선 택배 화물을 모아서 처리하는 집하장을 몇 개 마련했지만, 택배 화물이 각 집하장들 사이를 오갈 때 어떤 경로를 거쳐야 하는지 결정하지 못했다. 어떤 경로를 거칠지 정해서, 이를 경로표로 정리하는 것이 여러분이 할 일이다.</p>
<p><img src="https://www.acmicpc.net/JudgeOnline/upload/201005/taekbae.PNG" alt="img"></p>
<p>예시된 그래프에서 굵게 표시된 1, 2, 3, 4, 5, 6은 집하장을 나타낸다. 정점간의 간선은 두 집하장간에 화물 이동이 가능함을 나타내며, 가중치는 이동에 걸리는 시간이다. 이로부터 얻어내야 하는 경로표는 다음과 같다.</p>
<p><img src="https://www.acmicpc.net/JudgeOnline/upload/201005/tktk.PNG" alt="img"></p>
<p>경로표는 한 집하장에서 다른 집하장으로 최단경로로 화물을 이동시키기 위해 가장 먼저 거쳐야 하는 집하장을 나타낸 것이다. 예를 들어 4행 5열의 6은 4번 집하장에서 5번 집하장으로 최단 경로를 통해 가기 위해서는 제일 먼저 6번 집하장으로 이동해야 한다는 의미이다.</p>
<p>이와 같은 경로표를 구하는 프로그램을 작성하시오.</p>
<h2 id="입력">입력</h2>
<p>첫째 줄에 두 수 n과 m이 빈 칸을 사이에 두고 순서대로 주어진다. n은 집하장의 개수로 200이하의 자연수, m은 집하장간 경로의 개수로 10000이하의 자연수이다. 이어서 한 줄에 하나씩 집하장간 경로가 주어지는데, 두 집하장의 번호와 그 사이를 오가는데 필요한 시간이 순서대로 주어진다. 집하장의 번호들과 경로의 소요시간은 모두 1000이하의 자연수이다.</p>
<h2 id="출력">출력</h2>
<p>예시된 것과 같은 형식의 경로표를 출력한다.</p>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>문제를 보고 든 생각은 노드가 200개 밖에 안 되는 것이 보였다</li>
<li>200 * 200 * 200 = 8000000 =&gt; 플로이드 와샬로 문제를 해결 할 수 있다고 판단했다</li>
</ul>
<p>먼저 플로이드 와샬로 최단거리를 구하는 동시에</p>
<p>PointMap이라는 배열에 중간에 처음으로 거치는 자표를 넣어서 문제를 해결할려고 했다 </p>
<ol>
<li>먼저 PointMap를 자신의 노드 값으로 초기화 한다</li>
</ol>
<pre><code class="language-java">for (int i = 1; i &lt;= n; i++) {
    for (int j = 1; j &lt;= n; j++) {
        pointMap[i][j] = j;
    }
}</code></pre>
<ol start="2">
<li>플로이드 와샬을 사용해서 중간에 거치는 노드가 생기면 <code>pointMap[i][j] = pointMap[i][k]</code> 값을 저장한다</li>
</ol>
<pre><code class="language-java">for (int k = 1; k &lt;= n; k++) {
    for (int i = 1; i &lt;= n; i++) {
        for (int j = 1; j &lt;= n; j++) {
            if (map[i][j] &gt; map[i][k] + map[k][j]) {
                map[i][j] = map[i][k] + map[k][j];
                pointMap[i][j] = pointMap[i][k];
            }
        }
    }
}</code></pre>
<ol start="3">
<li>저장된 값을 출력한다</li>
</ol>
<pre><code class="language-java">StringBuilder sb = new StringBuilder();

for (int i = 1; i &lt;= n; i++) {
    for (int j = 1; j &lt;= n; j++) {
        if (i == j) {
            sb.append(&#39;-&#39;).append(&#39; &#39;);
            continue;
        }
        sb.append(pointMap[i][j]).append(&#39; &#39;);
    }
    sb.append(&#39;\n&#39;);
}

System.out.print(sb);</code></pre>
<h2 id="풀이-코드">풀이 코드</h2>
<pre><code class="language-java">package BOJ;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class BOJ_택배_HoonyCode {

    static int n, m;
    static int[][] map;
    static int[][] pointMap;

    private static final int MAX = 200 * 10000;

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] in = br.readLine().split(&quot; &quot;);

        n = Integer.parseInt(in[0]);
        m = Integer.parseInt(in[1]);

        map = new int[n + 1][n + 1];
        pointMap = new int[n + 1][n + 1];

        for (int i = 1; i &lt;= n; i++) {
            Arrays.fill(map[i], MAX);
        }

        for (int i = 1; i &lt;= n; i++) {
            for (int j = 1; j &lt;= n; j++) {
                pointMap[i][j] = j;
            }
        }

        int A, B, W;
        for (int i = 0; i &lt; m; i++) {
            in = br.readLine().split(&quot; &quot;);
            A = Integer.parseInt(in[0]);
            B = Integer.parseInt(in[1]);
            W = Integer.parseInt(in[2]);

            map[B][A] = map[A][B] = Math.min(map[A][B], W);
        }


        for (int k = 1; k &lt;= n; k++) {
            for (int i = 1; i &lt;= n; i++) {
                for (int j = 1; j &lt;= n; j++) {
                    if (map[i][j] &gt; map[i][k] + map[k][j]) {
                        map[i][j] = map[i][k] + map[k][j];
                        pointMap[i][j] = pointMap[i][k];
                    }
                }
            }
        }


        StringBuilder sb = new StringBuilder();

        for (int i = 1; i &lt;= n; i++) {
            for (int j = 1; j &lt;= n; j++) {
                if (i == j) {
                    sb.append(&#39;-&#39;).append(&#39; &#39;);
                    continue;
                }
                sb.append(pointMap[i][j]).append(&#39; &#39;);
            }
            sb.append(&#39;\n&#39;);
        }

        System.out.print(sb);
    }

}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] 멀리 뛰기 JAVA]]></title>
            <link>https://velog.io/@hoony-code/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EB%A9%80%EB%A6%AC-%EB%9B%B0%EA%B8%B0-JAVA</link>
            <guid>https://velog.io/@hoony-code/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EB%A9%80%EB%A6%AC-%EB%9B%B0%EA%B8%B0-JAVA</guid>
            <pubDate>Tue, 19 Apr 2022 11:34:08 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-설명">문제 설명</h2>
<p>효진이는 멀리 뛰기를 연습하고 있습니다. 효진이는 한번에 1칸, 또는 2칸을 뛸 수 있습니다. 칸이 총 4개 있을 때, 효진이는
(1칸, 1칸, 1칸, 1칸)
(1칸, 2칸, 1칸)
(1칸, 1칸, 2칸)
(2칸, 1칸, 1칸)
(2칸, 2칸)
의 5가지 방법으로 맨 끝 칸에 도달할 수 있습니다. 멀리뛰기에 사용될 칸의 수 n이 주어질 때, 효진이가 끝에 도달하는 방법이 몇 가지인지 알아내, 여기에 1234567를 나눈 나머지를 리턴하는 함수, solution을 완성하세요. 예를 들어 4가 입력된다면, 5를 return하면 됩니다.</p>
<h5 id="제한-사항">제한 사항</h5>
<ul>
<li>n은 1 이상, 2000 이하인 정수입니다.</li>
</ul>
<h5 id="입출력-예">입출력 예</h5>
<table>
<thead>
<tr>
<th>n</th>
<th>result</th>
</tr>
</thead>
<tbody><tr>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>3</td>
<td>3</td>
</tr>
</tbody></table>
<h5 id="입출력-예-설명">입출력 예 설명</h5>
<p>입출력 예 #1
위에서 설명한 내용과 같습니다.</p>
<p>입출력 예 #2
(2칸, 1칸)
(1칸, 2칸)
(1칸, 1칸, 1칸)
총 3가지 방법으로 멀리 뛸 수 있습니다.</p>
<h2 id="풀이-과정">풀이 과정</h2>
<blockquote>
<p>전형적인 dp 문제라고 생각하고 문제를 풀었다</p>
</blockquote>
<ul>
<li><p>점화식을 세우면</p>
<pre><code class="language-text">dp[i] = dp[i-1] + dp[i-2] 이다</code></pre>
</li>
<li><p>위의 점화식을 이용해서 코드를 구현한다</p>
</li>
</ul>
<h2 id="코드">코드</h2>
<pre><code class="language-java">class Solution {
    public long solution(int n) {
        long answer = 0;

        // dp 문제인것 같다
        final int div = 1234567;

        //n은 1이상 2000이하인 정수
        int[] dp = new int[2001];

        dp[1] = 1;
        dp[2] = 2;

        for (int i = 3; i &lt;= n ; i++){
            dp[i] = (dp[i-1] + dp[i-2])%div;
        }

        answer = dp[n];

        return answer;
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] 124 나라의 숫자 JAVA]]></title>
            <link>https://velog.io/@hoony-code/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-124-%EB%82%98%EB%9D%BC%EC%9D%98-%EC%88%AB%EC%9E%90</link>
            <guid>https://velog.io/@hoony-code/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-124-%EB%82%98%EB%9D%BC%EC%9D%98-%EC%88%AB%EC%9E%90</guid>
            <pubDate>Tue, 19 Apr 2022 11:24:59 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-설명">문제 설명</h2>
<p>124 나라가 있습니다. 124 나라에서는 10진법이 아닌 다음과 같은 자신들만의 규칙으로 수를 표현합니다.</p>
<ol>
<li>124 나라에는 자연수만 존재합니다.</li>
<li>124 나라에는 모든 수를 표현할 때 1, 2, 4만 사용합니다.</li>
</ol>
<p>예를 들어서 124 나라에서 사용하는 숫자는 다음과 같이 변환됩니다.</p>
<table>
<thead>
<tr>
<th>10진법</th>
<th>124 나라</th>
<th>10진법</th>
<th>124 나라</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>1</td>
<td>6</td>
<td>14</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td>7</td>
<td>21</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
<td>8</td>
<td>22</td>
</tr>
<tr>
<td>4</td>
<td>11</td>
<td>9</td>
<td>24</td>
</tr>
<tr>
<td>5</td>
<td>12</td>
<td>10</td>
<td>41</td>
</tr>
</tbody></table>
<p>자연수 n이 매개변수로 주어질 때, n을 124 나라에서 사용하는 숫자로 바꾼 값을 return 하도록 solution 함수를 완성해 주세요.</p>
<h5 id="제한사항">제한사항</h5>
<ul>
<li>n은 500,000,000이하의 자연수 입니다.</li>
</ul>
<h2 id="풀이-과정">풀이 과정</h2>
<blockquote>
<p>1, 2, 4가 3개이기 때문에 3의 배수로 문제를 풀 수 있다고 생각했다.</p>
</blockquote>
<ul>
<li>먼저 각 수를 3으로 나누어 보았다</li>
<li>나머지가 그 12일 때는 그 수가 되었고, 0일 때는 4를 나타내면 된다는 것을 발견했다.</li>
<li>마지막으로 나눈 나머지가 0일 때는 몫에서 -1을 해주면 되고 아니면 몫을 또 3으로 나누었을때 나머지가 그 자리수가 되는 것을 발견했다</li>
</ul>
<p>위의 내용을 코드로 구현하자면,</p>
<h2 id="코드">코드</h2>
<pre><code class="language-java">class Solution {
    public String solution(int n) {
        StringBuilder sb = new StringBuilder();

        int temp = n;
        int remain;

        while (temp &gt; 0) {
            remain = temp % 3;
            if (remain == 0){
                temp = temp/3 - 1;
            }else
                temp = temp/3;

            if (remain == 0) {
                sb.append(4);
            } else {
                sb.append(remain);
            }
        }

        return sb.reverse().toString();
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[백준] 팰린드롬 만들기 JAVA]]></title>
            <link>https://velog.io/@hoony-code/%EB%B0%B1%EC%A4%80-%ED%8C%B0%EB%A6%B0%EB%93%9C%EB%A1%AC-%EB%A7%8C%EB%93%A4%EA%B8%B0</link>
            <guid>https://velog.io/@hoony-code/%EB%B0%B1%EC%A4%80-%ED%8C%B0%EB%A6%B0%EB%93%9C%EB%A1%AC-%EB%A7%8C%EB%93%A4%EA%B8%B0</guid>
            <pubDate>Mon, 18 Apr 2022 08:57:48 GMT</pubDate>
            <description><![CDATA[<h2 id="문제">문제</h2>
<p>동호와 규완이는 212호에서 문자열에 대해 공부하고 있다. 규완이는 팰린드롬을 엄청나게 좋아한다. 팰린드롬이란 앞에서부터 읽으나 뒤에서부터 읽으나 같게 읽히는 문자열을 말한다.</p>
<p>동호는 규완이를 위한 깜짝 선물을 준비했다. 동호는 규완이가 적어놓고 간 문자열 S에 0개 이상의 문자를 문자열 뒤에 추가해서 팰린드롬을 만들려고 한다. 동호는 가능하면 가장 짧은 문자열을 만들려고 한다.</p>
<p>동호가 만들 수 있는 가장 짧은 팰린드롬의 길이를 출력하는 프로그램을 작성하시오.</p>
<h2 id="입력">입력</h2>
<p>첫째 줄에 문자열 S가 주어진다. S는 알파벳 소문자로만 이루어져 있고, 길이는 최대 50이다.</p>
<h2 id="출력">출력</h2>
<p>첫째 줄에 동호가 만들 수 있는 가장 짧은 팰린드롬의 길이를 출력한다.</p>
<h2 id="예제-입력-1-복사">예제 입력 1 복사</h2>
<pre><code>abab</code></pre><h2 id="예제-출력-1-복사">예제 출력 1 복사</h2>
<pre><code>5</code></pre><h2 id="풀이">풀이</h2>
<ul>
<li>팰린드롬이 홀수일 경우와 짝수일 경우로 나뉘어 풀 수 있었다.</li>
</ul>
<ul>
<li>길이가 홀수일 경우<ul>
<li>len-2 부터 시작해서 [i-J+1] [i+J]를 탐색한다</li>
</ul>
</li>
</ul>
<ul>
<li><p>길이가 짝수일 경우</p>
<ul>
<li>문자 길이가 2로 나눴을때 1이 남는다면 길이에 +1을 더해준다</li>
<li>len-2 부터 시작해서 [i-j+1] [i+j]를 탐색한다</li>
</ul>
</li>
<li><p>길이가 짧은 것을 answer에 담는다.</p>
</li>
</ul>
<h2 id="코드">코드</h2>
<pre><code class="language-java">public class Main {

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        char[] chars = br.readLine().toCharArray();

        int len = chars.length;

        int answer = (len-1) * 2 + 1;

        if (len == 1){
            System.out.println(1);
            return;
        }


        // 홀수일 경우
        loop : for (int i  = len-2 ; i &gt; len/2-1 ; i--){

            for (int j = 1; j + i &lt; len;  j++){
                if (chars[i-j] != chars[i+j]) continue loop;
            }

            answer = Math.min(answer, i * 2 + 1 );
        }


        // 짝수일 경우
        int end = len;
        if (len % 2 == 1) end++;
        loop : for (int i  = len-2 ; i &gt;= end/2-1 ; i--){

            for (int j = 1; j + i &lt; len;  j++){
                if (chars[i-j+1] != chars[i+j]) continue loop;
            }

            answer = Math.min(answer, (i+1)*2) ;
        }

        System.out.println(answer);
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[백준] 톱니바퀴 JAVA]]></title>
            <link>https://velog.io/@hoony-code/%EB%B0%B1%EC%A4%80-%ED%86%B1%EB%8B%88%EB%B0%94%ED%80%B4-JAVA</link>
            <guid>https://velog.io/@hoony-code/%EB%B0%B1%EC%A4%80-%ED%86%B1%EB%8B%88%EB%B0%94%ED%80%B4-JAVA</guid>
            <pubDate>Mon, 18 Apr 2022 08:51:49 GMT</pubDate>
            <description><![CDATA[<h2 id="문제">문제</h2>
<p>총 8개의 톱니를 가지고 있는 톱니바퀴 4개가 아래 그림과 같이 일렬로 놓여져 있다. 또, 톱니는 N극 또는 S극 중 하나를 나타내고 있다. 톱니바퀴에는 번호가 매겨져 있는데, 가장 왼쪽 톱니바퀴가 1번, 그 오른쪽은 2번, 그 오른쪽은 3번, 가장 오른쪽 톱니바퀴는 4번이다.</p>
<p><img src="https://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/14891/1.png" alt="img"></p>
<p>이때, 톱니바퀴를 총 K번 회전시키려고 한다. 톱니바퀴의 회전은 한 칸을 기준으로 한다. 회전은 시계 방향과 반시계 방향이 있고, 아래 그림과 같이 회전한다.</p>
<p><img src="https://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/14891/2.png" alt="img"></p>
<p><img src="https://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/14891/3.png" alt="img"></p>
<p>톱니바퀴를 회전시키려면, 회전시킬 톱니바퀴와 회전시킬 방향을 결정해야 한다. 톱니바퀴가 회전할 때, 서로 맞닿은 극에 따라서 옆에 있는 톱니바퀴를 회전시킬 수도 있고, 회전시키지 않을 수도 있다. 톱니바퀴 A를 회전할 때, 그 옆에 있는 톱니바퀴 B와 서로 맞닿은 톱니의 극이 다르다면, B는 A가 회전한 방향과 반대방향으로 회전하게 된다. 예를 들어, 아래와 같은 경우를 살펴보자.</p>
<p><img src="https://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/14891/4.png" alt="img"></p>
<p>두 톱니바퀴의 맞닿은 부분은 초록색 점선으로 묶여있는 부분이다. 여기서, 3번 톱니바퀴를 반시계 방향으로 회전했다면, 4번 톱니바퀴는 시계 방향으로 회전하게 된다. 2번 톱니바퀴는 맞닿은 부분이 S극으로 서로 같기 때문에, 회전하지 않게 되고, 1번 톱니바퀴는 2번이 회전하지 않았기 때문에, 회전하지 않게 된다. 따라서, 아래 그림과 같은 모양을 만들게 된다.</p>
<p><img src="https://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/14891/5.png" alt="img"></p>
<p>위와 같은 상태에서 1번 톱니바퀴를 시계 방향으로 회전시키면, 2번 톱니바퀴가 반시계 방향으로 회전하게 되고, 2번이 회전하기 때문에, 3번도 동시에 시계 방향으로 회전하게 된다. 4번은 3번이 회전하지만, 맞닿은 극이 같기 때문에 회전하지 않는다. 따라서, 아래와 같은 상태가 된다.</p>
<p><img src="https://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/14891/6.png" alt="img"></p>
<p>톱니바퀴의 초기 상태와 톱니바퀴를 회전시킨 방법이 주어졌을 때, 최종 톱니바퀴의 상태를 구하는 프로그램을 작성하시오.</p>
<h2 id="입력">입력</h2>
<p>첫째 줄에 1번 톱니바퀴의 상태, 둘째 줄에 2번 톱니바퀴의 상태, 셋째 줄에 3번 톱니바퀴의 상태, 넷째 줄에 4번 톱니바퀴의 상태가 주어진다. 상태는 8개의 정수로 이루어져 있고, 12시방향부터 시계방향 순서대로 주어진다. N극은 0, S극은 1로 나타나있다.</p>
<p>다섯째 줄에는 회전 횟수 K(1 ≤ K ≤ 100)가 주어진다. 다음 K개 줄에는 회전시킨 방법이 순서대로 주어진다. 각 방법은 두 개의 정수로 이루어져 있고, 첫 번째 정수는 회전시킨 톱니바퀴의 번호, 두 번째 정수는 방향이다. 방향이 1인 경우는 시계 방향이고, -1인 경우는 반시계 방향이다.</p>
<h2 id="출력">출력</h2>
<p>총 K번 회전시킨 이후에 네 톱니바퀴의 점수의 합을 출력한다. 점수란 다음과 같이 계산한다.</p>
<ul>
<li>1번 톱니바퀴의 12시방향이 N극이면 0점, S극이면 1점</li>
<li>2번 톱니바퀴의 12시방향이 N극이면 0점, S극이면 2점</li>
<li>3번 톱니바퀴의 12시방향이 N극이면 0점, S극이면 4점</li>
<li>4번 톱니바퀴의 12시방향이 N극이면 0점, S극이면 8점</li>
</ul>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>먼저 시계방향으로 돌 때</li>
<li>반시계방향으로 돌 때</li>
<li>톱니바퀴의 변화를 구현한다</li>
</ul>
<pre><code class="language-java">public static void rotate(int[] spins, int state) {
    if (state == 1) { // 시계방향

        int temp = spins[7];

        for (int i = 7; i &gt; 0; i--) {
            spins[i] = spins[i - 1];
        }

        spins[0] = temp;

    } else { // 반시계 방향

        int temp = spins[0];

        for (int i = 0; i &lt; 7; i++) {
            spins[i] = spins[(i + 1)];
        }

        spins[7] = temp;
    }
}</code></pre>
<ul>
<li>위의 구현이 끝나면</li>
<li>오른쪽 왼쪽 톱니바퀴가 돌 수 있는지 확인하고 탐색한다</li>
</ul>
<pre><code class="language-java">for (int i = 0; i &lt; K; i++) {
    in = br.readLine().split(&quot; &quot;);
    N = Integer.parseInt(in[0]) - 1;
    S = Integer.parseInt(in[1]); // 1시게 -1 반시계 // 0 멈춤

    Arrays.fill(v, false);
    queue.clear();
    queue.offer(new int[]{N, S});
    v[N] = true;

    int[] cur;
    while (!queue.isEmpty()) {
        cur = queue.poll();

        int nx;
        for (int d = 0; d &lt; 2; d++) {
            nx = cur[0] + dx[d];

            if (nx &lt; 0 || nx &gt; 3) continue;
            if (v[nx]) continue;
            v[nx] = true;
            //왼쪽일 떄
            if (d == 0) {
                if (spins[nx][2] == spins[cur[0]][6]) continue;
                queue.offer(new int[]{nx, -cur[1]});
            } else {//오른쪽 일 떄
                if (spins[nx][6] == spins[cur[0]][2]) continue;
                queue.offer(new int[]{nx, -cur[1]});
            }
        }

        rotate(spins[cur[0]], cur[1]);
    }
}</code></pre>
<ul>
<li>마지막으로 톱니바퀴 점수를 answer에 저장하고 출력한다.</li>
</ul>
<pre><code class="language-java">for (int i = 0; i &lt; 4; i++) {
    answer += (spins[i][0] &lt;&lt; i);
}</code></pre>
<pre><code class="language-java">import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

public class Main {

    static int[] dx = {-1, 1};

    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        // 톱니바퀴
        int[][] spins = new int[4][8];
        int answer = 0;
        String[] in;

        for (int i = 0; i &lt; 4; i++) {
            in = br.readLine().split(&quot;&quot;);
            for (int j = 0; j &lt; 8; j++) {
                spins[i][j] = Integer.parseInt(in[j]);
            }
        }


        // 회전 횟수
        int K = Integer.parseInt(br.readLine());

        int N;
        int S;

        boolean[] v = new boolean[4];
        Queue&lt;int[]&gt; queue = new LinkedList&lt;&gt;();

        for (int i = 0; i &lt; K; i++) {
            in = br.readLine().split(&quot; &quot;);
            N = Integer.parseInt(in[0]) - 1;
            S = Integer.parseInt(in[1]); // 1시게 -1 반시계 // 0 멈춤

            Arrays.fill(v, false);
            queue.clear();
            queue.offer(new int[]{N, S});
            v[N] = true;

            int[] cur;
            while (!queue.isEmpty()) {
                cur = queue.poll();

                int nx;
                for (int d = 0; d &lt; 2; d++) {
                    nx = cur[0] + dx[d];

                    if (nx &lt; 0 || nx &gt; 3) continue;
                    if (v[nx]) continue;
                    v[nx] = true;
                    //왼쪽일 떄
                    if (d == 0) {
                        if (spins[nx][2] == spins[cur[0]][6]) continue;
                        queue.offer(new int[]{nx, -cur[1]});
                    } else {//오른쪽 일 떄
                        if (spins[nx][6] == spins[cur[0]][2]) continue;
                        queue.offer(new int[]{nx, -cur[1]});
                    }
                }

                rotate(spins[cur[0]], cur[1]);
            }
        }


        for (int i = 0; i &lt; 4; i++) {
            answer += (spins[i][0] &lt;&lt; i);
        }

        System.out.println(answer);

    }


    public static void rotate(int[] spins, int state) {
        if (state == 1) { // 시계방향

            int temp = spins[7];

            for (int i = 7; i &gt; 0; i--) {
                spins[i] = spins[i - 1];
            }

            spins[0] = temp;

        } else { // 반시계 방향

            int temp = spins[0];

            for (int i = 0; i &lt; 7; i++) {
                spins[i] = spins[(i + 1)];
            }

            spins[7] = temp;
        }
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[Pattern] Factory Method]]></title>
            <link>https://velog.io/@hoony-code/Pettern-Factory-Method-Pattern</link>
            <guid>https://velog.io/@hoony-code/Pettern-Factory-Method-Pattern</guid>
            <pubDate>Mon, 18 Apr 2022 08:20:12 GMT</pubDate>
            <description><![CDATA[<h2 id="팩토리-메서드-패턴이란">팩토리 메서드 패턴이란?</h2>
<blockquote>
<p>팩토리 매서드 패턴은 객체를 생성하는 공장을 만드는 것으로서 어떤 객체를 만드는 지는 자식 클래스에서 결정하게 하는 디자인 패턴이다.</p>
</blockquote>
<ul>
<li>객체를 생성하기 위해 인터페이스를 정의하지만, 어떤 클래스의 인스턴스를 생성할지에 대한 결정은 서브 클래스가 내리도록 하는 패턴</li>
<li>하위 클래스에서 팩토리 매서드를 <code>override</code>해서 객체를 반환하게 하는 패턴이다.</li>
</ul>
<h2 id="왜-사용하는가">왜 사용하는가?</h2>
<ul>
<li>어떤 클래스가 자신이 생성해야 하는 객체의 클래스를 예측할 수 없을 때</li>
<li>생성할 객체를 기술하는 책임을 자신의 서브클래스가 지정했으면 할 때</li>
<li>객체 생성의 책임을 몇 개의 보조 서브클래스 가운데 하나에게 위임하고, 어떤 서브클래스가 위임자인지에 대한 정보를 국소화 시키고 싶을 때</li>
</ul>
<h2 id="팩토리-메서드-구조">팩토리 메서드 구조</h2>
<p><img src="https://velog.velcdn.com/images/hoony-code/post/f7f77708-5cfe-485f-a27d-5c5c06961a3a/image.png" alt=""></p>
<h3 id="product">Product</h3>
<ul>
<li>팩토리 매서드가 생성하는 객체의 인터페이스를 정의한다.</li>
</ul>
<h3 id="concreteproduct">ConcreteProduct</h3>
<ul>
<li>Product 클래스에 정의된 인터페이스를 실제로 구현하는 클래스</li>
</ul>
<h3 id="creator">Creator</h3>
<ul>
<li>Product 타입의 객체를 반환하는 팩토리 매서드를 선언하는 클래스</li>
<li>팩토리 매서드를 기본적으로 구현, ConcreteProduct 객체를 반환한다.</li>
<li>Product 객체의 생성을 위해 팩토리 매서드를 호출한다.</li>
</ul>
<h3 id="concretecreator">ConcreteCreator</h3>
<ul>
<li>팩토리 메서드를 재정의하여 ConcreteProduct의 인스턴스를 반환</li>
</ul>
<h2 id="구현시-고려할-점">구현시 고려할 점</h2>
<h4 id="팩토리-매서드-패턴의-구현-방법은-크게-두가지가-있다">팩토리 매서드 패턴의 구현 방법은 크게 두가지가 있다</h4>
<ul>
<li>Creator를 추상 클래스로 정의하고, 팩토리 매서드는 abstract로 선언하는 방법</li>
<li>Creator를 구체 클래스이고, 팩토리 메서드의 기본 구현을 제공하는 방법</li>
</ul>
<h4 id="팩토리-매서드의-인자를-통해-다양한-product를-생성하게-된다">팩토리 매서드의 인자를 통해 다양한 Product를 생성하게 된다.</h4>
<ul>
<li>팩토리 매서드에 잘못된 인자가 들어올 경우의 런타임 에러 처리에 대해 고민할 것</li>
<li>Enum 등을 사용하는 것도 고려할 필요가 있다.</li>
</ul>
<h2 id="장점과-단점">장점과 단점</h2>
<h4 id="장점">장점</h4>
<ul>
<li>객체 생성에 관련한 코드와 동작 코드를 분리할 수 있다.</li>
</ul>
<h2 id="예시">예시</h2>
<table>
<thead>
<tr>
<th></th>
<th>궁수</th>
<th>전사</th>
</tr>
</thead>
<tbody><tr>
<td>시작 힘/민첩</td>
<td>100/100</td>
<td>100/100</td>
</tr>
<tr>
<td>레벨업 시 증가하는 힘/민첩</td>
<td>10/30</td>
<td>30/10</td>
</tr>
</tbody></table>
<ul>
<li>궁수와 전사 캐릭터가 있습니다.</li>
<li>레벨업시 두 직업간의 차이가 계속 생길 것을 대비하여, 다른 클래스를 통해 두 개의 클래스를 생성합니다.<ul>
<li>이러한 과정에서 신규캐릭터를 인스턴스화 하는 경우, 팩토리 패턴을 사용하여 이를 구성하겠습니다.</li>
</ul>
</li>
</ul>
<p><img src="https://velog.velcdn.com/images/hoony-code/post/2e10119c-38ec-4be7-9ec7-a5ff3178a48c/image.png" alt=""></p>
<table>
<thead>
<tr>
<th>GOF</th>
<th>설명</th>
<th>our class</th>
</tr>
</thead>
<tbody><tr>
<td>Creator</td>
<td>추사클래스이며 구체클래스의 부모클래스로,<br />Product 타입을 반환하는 팩토리매서드 (abstract method)를 가지고 있습니다.</td>
<td>CharacterCreator</td>
</tr>
<tr>
<td>ConcreteCreator</td>
<td>팩토리 매서드를 재정의하여 구체 클래스(ConcreteProduct)를 리턴합니다.</td>
<td>WarriorCreator<br />ArcherCreator</td>
</tr>
<tr>
<td>Product</td>
<td>팩토리 매서드가 리턴하는 클래스의 추상클래스입니다.</td>
<td>Character</td>
</tr>
<tr>
<td>ConcreteProduct</td>
<td>Product 클래스에 정의된 매서드가 구현된 구체 클래스입니다.</td>
<td>Warrior<br />Archer</td>
</tr>
</tbody></table>
<h2 id="코드">코드</h2>
<p><code>Character.java</code></p>
<pre><code class="language-java">package Velog;

public abstract class Character {

    protected int STR;
    protected int DEX;

    public abstract void levelUp();

    public int getSTR() {
        return STR;
    }

    public void setSTR(int STR) {
        this.STR = STR;
    }

    public int getDEX() {
        return DEX;
    }

    public void setDEX(int DEX) {
        this.DEX = DEX;
    }
}
</code></pre>
<p><code>Archer.java</code></p>
<pre><code class="language-java">package Velog;

public class Archer extends Character {
    @Override
    public void levelUp() {
        this.STR += 10;
        this.DEX += 30;
    }
}
</code></pre>
<p><code>Warrior.java</code></p>
<pre><code class="language-java">package Velog;

public class Warrior extends Character {

    @Override
    public void levelUp() {
        this.STR += 30;
        this.DEX += 10;
    }
}
</code></pre>
<hr>
<p><code>CharacterCreator.java</code></p>
<pre><code class="language-java">package Velog;

public abstract class CharacterCreator {

    public Character CharacterCreator() {
        final Character character = character();

        character.setDEX(100);
        character.setSTR(100);

        return character;
    }


    protected abstract Character character();
}
</code></pre>
<p><code>ArcherCreator.java</code></p>
<pre><code class="language-java">package Velog;

public class ArcherCreator extends CharacterCreator{
    @Override
    protected Character character() {
        return new Archer();
    }
}
</code></pre>
<p><code>warriorCreator.java</code></p>
<pre><code class="language-java">package Velog;

public class WarriorCreator extends CharacterCreator{
    @Override
    protected Character character() {
        return new Warrior();
    }
}
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[Java] String, StringBuffer, StringBuilder 차이 및 장단점]]></title>
            <link>https://velog.io/@hoony-code/Java-String-StringBuffer-StringBuilder-%EC%B0%A8%EC%9D%B4-%EB%B0%8F-%EC%9E%A5%EB%8B%A8%EC%A0%90</link>
            <guid>https://velog.io/@hoony-code/Java-String-StringBuffer-StringBuilder-%EC%B0%A8%EC%9D%B4-%EB%B0%8F-%EC%9E%A5%EB%8B%A8%EC%A0%90</guid>
            <pubDate>Sun, 10 Apr 2022 15:39:48 GMT</pubDate>
            <description><![CDATA[<p>Java에서 문자열을 다루는 대표적인 클래스로 <code>String</code>, <code>StringBuffer</code>, <code>StringBuilder</code>가 있다.</p>
<p>연산이 많이 않을때는 특별한 이슈가 발생할 가능성이 거의 없지만, 연산횟수가 많아지거나 멀티스레드, 경쟁 상태(Race Condition) 등의 상황이 자주 발생하면 각 클래스의 특징을 이해하고 상황에 맞는 적절한 클래스를 사용해야 한다.</p>
<p><code>String</code>과 <code>StringBuffer</code>와 <code>StringBuilder</code>의 기본적인 차이는 <code>String</code>은 불변(Immutable), <code>StringBuffer</code>와 <code>StringBuilder</code>는 변함(Mutable) 이다.</p>
<h2 id=""></h2>
<h2 id="1-string">1. String</h2>
<p>string 객체는 한번 생성됨면 할당된 메모리 공간이 변하지 않는다.</p>
<p><code>concat</code> 메서드 또는 + 연산자를 통해 기존에 생성된 String 클래스 객체 문자열에 다른 문자열을 붙여도 기존 문자열에 새로운 문자열을 붙이는 것이 아니라 새로운 String 객체를 만든 후 새 String 객체에 연결된 문자열을 저장하고 그 객체를 참조하도록 하는 것이다.</p>
<p>즉, String 클래스 객체는 Heap 메모리 영역에 생성하고 한번 생성된 객체 내부 내용을 변화시킬 수 없다.</p>
<p>String 객체는 문자열 연산이 많은 경우 성능이 좋지 않다 </p>
<pre><code class="language-java">String str = &quot;Hello&quot;; // 메모리에 Hello 담는다.

str = str.concat(&quot; World&quot;); //기존 메로리 Hello에 값을 붙이는 것이 아니라 새로운 메모리에 Hello World를 담는다.</code></pre>
<h2 id="2-stringbuffer와-stringbuilder">2. StringBuffer와 StringBuilder</h2>
<p>StringBuffer와 StringBuilder는 String과 다르게 동작한다.</p>
<p>문자열 연산 등으로 기존 객체의 공간이 부족하게 되는 경우 기존의 버퍼 크기를 늘리면 유연하게 동작한다. StringBuffer와 StringBuilder 클래스가 제공하는 메서드는 서로 동일하다.</p>
<h3 id="차이점">차이점</h3>
<table>
<thead>
<tr>
<th></th>
<th>StringBuffer</th>
<th>StringBuilder</th>
</tr>
</thead>
<tbody><tr>
<td>동기화</td>
<td>동기화 보장 o</td>
<td>동기화 보장 x</td>
</tr>
</tbody></table>
<ul>
<li>멀티스레드 환경이라면 값의 동기화 보장을 위해 StringBuffer를 사용하는 것이 좋다. </li>
<li>단일스레드 환경이라면 StringBuilder를 사용하는 것이 좋다. <ul>
<li>StringBuffer는 동기화 관련 처리로 인해 StringBuilder에 비해 성능이 좋지 않다</li>
</ul>
</li>
</ul>
<pre><code class="language-java">StringBuilder sb = new StringBuilder();
sb.append(&quot;Hello&quot;); // 기존 메모리를 늘려 Hello 추가
sb.append(&quot; &quot;).append(&quot;world&quot;) // 기존 메모리를 늘려 &quot; &quot;와 &quot;world&quot; 추가</code></pre>
<h2 id="3-정리">3. 정리</h2>
<blockquote>
<p>보통 사용할 떄 String을 사용하고,</p>
<p> 출력값이 많아지거나 String에서 + 연산자나 , concat() 메서드 사용이 많아진다면 StringBuilder를 사용하자!</p>
</blockquote>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] 징검다리 JAVA]]></title>
            <link>https://velog.io/@hoony-code/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EC%A7%95%EA%B2%80%EB%8B%A4%EB%A6%AC-JAVA</link>
            <guid>https://velog.io/@hoony-code/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EC%A7%95%EA%B2%80%EB%8B%A4%EB%A6%AC-JAVA</guid>
            <pubDate>Sun, 10 Apr 2022 14:54:27 GMT</pubDate>
            <description><![CDATA[<h6 id="문제-설명">문제 설명</h6>
<p>출발지점부터 distance만큼 떨어진 곳에 도착지점이 있습니다. 그리고 그사이에는 바위들이 놓여있습니다. 바위 중 몇 개를 제거하려고 합니다.
예를 들어, 도착지점이 25만큼 떨어져 있고, 바위가 [2, 14, 11, 21, 17] 지점에 놓여있을 때 바위 2개를 제거하면 출발지점, 도착지점, 바위 간의 거리가 아래와 같습니다.</p>
<table>
<thead>
<tr>
<th>제거한 바위의 위치</th>
<th>각 바위 사이의 거리</th>
<th>거리의 최솟값</th>
</tr>
</thead>
<tbody><tr>
<td>[21, 17]</td>
<td>[2, 9, 3, 11]</td>
<td>2</td>
</tr>
<tr>
<td>[2, 21]</td>
<td>[11, 3, 3, 8]</td>
<td>3</td>
</tr>
<tr>
<td>[2, 11]</td>
<td>[14, 3, 4, 4]</td>
<td>3</td>
</tr>
<tr>
<td>[11, 21]</td>
<td>[2, 12, 3, 8]</td>
<td>2</td>
</tr>
<tr>
<td>[2, 14]</td>
<td>[11, 6, 4, 4]</td>
<td>4</td>
</tr>
</tbody></table>
<p>위에서 구한 거리의 최솟값 중에 가장 큰 값은 4입니다.</p>
<p>출발지점부터 도착지점까지의 거리 distance, 바위들이 있는 위치를 담은 배열 rocks, 제거할 바위의 수 n이 매개변수로 주어질 때, 바위를 n개 제거한 뒤 각 지점 사이의 거리의 최솟값 중에 가장 큰 값을 return 하도록 solution 함수를 작성해주세요.</p>
<h5 id="제한사항">제한사항</h5>
<ul>
<li>도착지점까지의 거리 distance는 1 이상 1,000,000,000 이하입니다.</li>
<li>바위는 1개 이상 50,000개 이하가 있습니다.</li>
<li>n 은 1 이상 <code>바위의 개수</code> 이하입니다.</li>
</ul>
<h5 id="입출력-예">입출력 예</h5>
<table>
<thead>
<tr>
<th>distance</th>
<th>rocks</th>
<th>n</th>
<th>return</th>
</tr>
</thead>
<tbody><tr>
<td>25</td>
<td>[2, 14, 11, 21, 17]</td>
<td>2</td>
<td>4</td>
</tr>
</tbody></table>
<h5 id="입출력-예-설명">입출력 예 설명</h5>
<p>문제에 나온 예와 같습니다.</p>
<p><a href="http://contest.usaco.org/DEC06.htm">출처</a></p>
<p>※ 공지 - 2020년 2월 17일 테스트케이스가 추가되었습니다.</p>
<h5 id="문제-풀이">문제 풀이</h5>
<p>문제를 풀 때 먼저 생각한 방법은 n개를 고르고 완전 탐색하는 방법이었다 하지만 그 방법을 실행했을 때</p>
<p>최악의 경우일 때 <code>시간 초과</code>를 발생시킨다는 것을 알고 다른 방법을 찾았다.</p>
<p>다른 방법은 문제를 다르게 생각해보는 것이었다.</p>
<p><code>특정 값에서 n개를 지울 수 있는지?</code>를 생각하는 방법이었다.</p>
<p>특정 값(돌의 길의 최솟값)보다 작은 사이에 값을 가질 때마다 제거할 수 있는 돌로 <code>remove++</code> 해준다</p>
<p>모든 거리를 비교하고 나서, 제거할 수 있는 돌이 n개보다 큰 경우, 작은 경우에 따라서 범위를 재 조정해간다</p>
<h5 id="코드">코드</h5>
<pre><code class="language-java">import java.util.Arrays;

class Solution {
    public int solution(int distance, int[] rocks, int n) {
        int answer = 0;

        Arrays.sort(rocks);

        int start = 0;
        int end = distance;

        while (start &lt;= end) {
            int mid = (start + end) / 2;
            int remove = 0;
            int prev = 0;

            for (int i = 0; i &lt; rocks.length; i++) {

                if (rocks[i] - prev &lt; mid) {
                    remove++;
                } else {
                    prev = rocks[i];
                }

            }

            if (distance - prev &lt; mid) remove++;

            if (remove &lt;= n) {
                answer = Math.max(answer, mid);

                start = mid + 1;
            } else {
                end = mid - 1;
            }
        }


        return answer;
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] 단어 변환 JAVA]]></title>
            <link>https://velog.io/@hoony-code/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EB%8B%A8%EC%96%B4-%EB%B3%80%ED%99%98-JAVA</link>
            <guid>https://velog.io/@hoony-code/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EB%8B%A8%EC%96%B4-%EB%B3%80%ED%99%98-JAVA</guid>
            <pubDate>Tue, 29 Mar 2022 14:32:59 GMT</pubDate>
            <description><![CDATA[<h2 id="문제">문제</h2>
<hr>
<p>두 개의 단어 begin, target과 단어의 집합 words가 있습니다. 아래와 같은 규칙을 이용하여 begin에서 target으로 변환하는 가장 짧은 변환 과정을 찾으려고 합니다.</p>
<pre><code>1. 한 번에 한 개의 알파벳만 바꿀 수 있습니다.
2. words에 있는 단어로만 변환할 수 있습니다.</code></pre><p>예를 들어 begin이 &quot;hit&quot;, target가 &quot;cog&quot;, words가 [&quot;hot&quot;,&quot;dot&quot;,&quot;dog&quot;,&quot;lot&quot;,&quot;log&quot;,&quot;cog&quot;]라면 &quot;hit&quot; -&gt; &quot;hot&quot; -&gt; &quot;dot&quot; -&gt; &quot;dog&quot; -&gt; &quot;cog&quot;와 같이 4단계를 거쳐 변환할 수 있습니다.</p>
<p>두 개의 단어 begin, target과 단어의 집합 words가 매개변수로 주어질 때, 최소 몇 단계의 과정을 거쳐 begin을 target으로 변환할 수 있는지 return 하도록 solution 함수를 작성해주세요.</p>
<h5 id="제한사항">제한사항</h5>
<ul>
<li>각 단어는 알파벳 소문자로만 이루어져 있습니다.</li>
<li>각 단어의 길이는 3 이상 10 이하이며 모든 단어의 길이는 같습니다.</li>
<li>words에는 3개 이상 50개 이하의 단어가 있으며 중복되는 단어는 없습니다.</li>
<li>begin과 target은 같지 않습니다.</li>
<li>변환할 수 없는 경우에는 0를 return 합니다.</li>
</ul>
<h5 id="입출력-예">입출력 예</h5>
<table>
<thead>
<tr>
<th>begin</th>
<th>target</th>
<th>words</th>
<th>return</th>
</tr>
</thead>
<tbody><tr>
<td>&quot;hit&quot;</td>
<td>&quot;cog&quot;</td>
<td>[&quot;hot&quot;, &quot;dot&quot;, &quot;dog&quot;, &quot;lot&quot;, &quot;log&quot;, &quot;cog&quot;]</td>
<td>4</td>
</tr>
<tr>
<td>&quot;hit&quot;</td>
<td>&quot;cog&quot;</td>
<td>[&quot;hot&quot;, &quot;dot&quot;, &quot;dog&quot;, &quot;lot&quot;, &quot;log&quot;]</td>
<td>0</td>
</tr>
</tbody></table>
<h5 id="입출력-예-설명">입출력 예 설명</h5>
<p>예제 #1
문제에 나온 예와 같습니다.</p>
<p>예제 #2
target인 &quot;cog&quot;는 words 안에 없기 때문에 변환할 수 없습니다.</p>
<h2 id="문제-풀이">문제 풀이</h2>
<hr>
<p><code>넓이 우선 탐색을 사용하자</code></p>
<ol>
<li>단어와 과정의 수를 넣을 <code>Pair</code>라는 클래스를 만들자</li>
<li><code>Queue</code>를 만들어서 <code>new pair(과정의수 : 0, 시작 단어 : begin)</code>을 넣습니다.</li>
<li><code>queue</code>에서 데이터를 뽑고 <code>str</code>와 한 문자가 다른 문자열을 <code>words</code>에서 찾아 다시 <code>queue</code>에 넣습니다</li>
<li>위의 과정을 반복하면서 <code>target</code> 문자열을 찾습니다.</li>
</ol>
<p>없을 경우를 처리할때</p>
<p><code>cnt</code>가 <code>words</code>의 개수보다 커지면 모든 경우를 다 둘러보았기 때문에 없다고 판단하면 됩니다.</p>
<p>아래와 같은 if문으로 처리해줍니다.</p>
<pre><code class="language-java">if (cur.str.equals(target)) {
  answer = cur.cnt;
  break;
}</code></pre>
<p><code>코드</code></p>
<pre><code class="language-java">import java.util.*;

class Solution {
    public int solution(String begin, String target, String[] words) {
        int answer = 100;
        Queue&lt;Pair&gt; queue = new LinkedList&lt;&gt;();
        queue.offer(new Pair(0, begin));
        int len = words.length;
        Pair cur;

        while (!queue.isEmpty()) {
            cur = queue.poll();

            if (cur.str.equals(target)) {
                answer = cur.cnt;
                break;
            }
            if (cur.cnt &gt; len){
                continue;
            }

            for (String word : words) {
                int cnt = 0;

                for (int i = 0 ; i &lt; begin.length() ; i++){
                    if (word.charAt(i) != cur.str.charAt(i)) {
                        cnt++;
                    }
                }

                if (cnt == 1){
                    queue.offer(new Pair(cur.cnt + 1, word));
                }
            }

        }

        return answer == 100 ? 0 : answer;
    }
}

class Pair{
    int cnt;
    String str;

    public Pair(int cnt, String str) {
        this.cnt = cnt;
        this.str = str;
    }
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] 네트워크 JAVA]]></title>
            <link>https://velog.io/@hoony-code/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4</link>
            <guid>https://velog.io/@hoony-code/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4</guid>
            <pubDate>Mon, 28 Mar 2022 23:35:17 GMT</pubDate>
            <description><![CDATA[<h6 id="문제-설명">문제 설명</h6>
<p>네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있을 때 컴퓨터 A와 컴퓨터 C도 간접적으로 연결되어 정보를 교환할 수 있습니다. 따라서 컴퓨터 A, B, C는 모두 같은 네트워크 상에 있다고 할 수 있습니다.</p>
<p>컴퓨터의 개수 n, 연결에 대한 정보가 담긴 2차원 배열 computers가 매개변수로 주어질 때, 네트워크의 개수를 return 하도록 solution 함수를 작성하시오.</p>
<h5 id="제한사항">제한사항</h5>
<ul>
<li>컴퓨터의 개수 n은 1 이상 200 이하인 자연수입니다.</li>
<li>각 컴퓨터는 0부터 <code>n-1</code>인 정수로 표현합니다.</li>
<li>i번 컴퓨터와 j번 컴퓨터가 연결되어 있으면 computers[i][j]를 1로 표현합니다.</li>
<li>computer[i][i]는 항상 1입니다.</li>
</ul>
<h5 id="입출력-예">입출력 예</h5>
<table>
<thead>
<tr>
<th>n</th>
<th>computers</th>
<th>return</th>
</tr>
</thead>
<tbody><tr>
<td>3</td>
<td>[[1, 1, 0], [1, 1, 0], [0, 0, 1]]</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>[[1, 1, 0], [1, 1, 1], [0, 1, 1]]</td>
<td>1</td>
</tr>
</tbody></table>
<h5 id="입출력-예-설명">입출력 예 설명</h5>
<p>예제 #1
아래와 같이 2개의 네트워크가 있습니다.
<img src="https://grepp-programmers.s3.amazonaws.com/files/ybm/5b61d6ca97/cc1e7816-b6d7-4649-98e0-e95ea2007fd7.png" alt="image0.png" style="zoom: 50%; " /></p>
<p>예제 #2
아래와 같이 1개의 네트워크가 있습니다.
<img src="https://grepp-programmers.s3.amazonaws.com/files/ybm/7554746da2/edb61632-59f4-4799-9154-de9ca98c9e55.png" alt="image1.png" style="zoom: 50%;" /></p>
<h2 id="풀이-과정">풀이 과정</h2>
<p><code>BFS(넓이 우선 탐색)</code>을 이용해서 문제를 풀자</p>
<ol>
<li><code>boolean[] v</code> 배열을 이용해서 탐색한 곳은 <code>true</code>로 만들어 준다</li>
<li><code>v[i] = false</code>이면 그 지점부터 연결된 곳들을 모두 탐색한다</li>
<li>탐색을 시작할 때마다 answer을 1증가 시키면 답이 된다</li>
</ol>
<p><img src = "https://images.velog.io/images/hoony-code/post/b753b305-f406-41e3-b905-f55172de42ec/image-20220329083145972.png"
     alt="image2.png" style="zoom:33%" /></p>
<pre><code class="language-java">package PROGRAMMERS;

import java.util.LinkedList;
import java.util.Queue;

public class PRO_네트워크_HoonyCode {

    class Solution {

        boolean[] v;

        public int solution(int n, int[][] computers) {
            int answer = 0;

            //bfs로 그 점이랑 연결되어 있는 부분을 찾아 내자
            v = new boolean[n];

            for (int i = 0; i &lt; n; i++) {
                if (v[i]) continue;
                answer++;
                bfs(i, computers, n);
            }

            return answer;
        }


        public void bfs(int start, int[][] computers, int size) {
            Queue&lt;Integer&gt; que = new LinkedList&lt;&gt;();
            que.offer(start);
            v[start] = true;


            int cur;
            while (!que.isEmpty()) {
                cur = que.poll();

                for (int i = 0; i &lt; size; i++) {
                    if (computers[cur][i] != 1) continue;
                    if (v[i]) continue;

                    v[i] = true;
                    que.offer(i);
                }
            }

        }
    }
}
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] 등굣길 JAVA]]></title>
            <link>https://velog.io/@hoony-code/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EB%93%B1%EA%B5%A3%EA%B8%B8</link>
            <guid>https://velog.io/@hoony-code/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EB%93%B1%EA%B5%A3%EA%B8%B8</guid>
            <pubDate>Sun, 27 Mar 2022 13:24:53 GMT</pubDate>
            <description><![CDATA[<h2 id="문제">문제</h2>
<hr>
<p>계속되는 폭우로 일부 지역이 물에 잠겼습니다. 물에 잠기지 않은 지역을 통해 학교를 가려고 합니다. 집에서 학교까지 가는 길은 m x n 크기의 격자모양으로 나타낼 수 있습니다.</p>
<p>아래 그림은 m = 4, n = 3 인 경우입니다.</p>
<p><img src="https://grepp-programmers.s3.amazonaws.com/files/ybm/056f54e618/f167a3bc-e140-4fa8-a8f8-326a99e0f567.png" alt="image0.png"></p>
<p>가장 왼쪽 위, 즉 집이 있는 곳의 좌표는 (1, 1)로 나타내고 가장 오른쪽 아래, 즉 학교가 있는 곳의 좌표는 (m, n)으로 나타냅니다.</p>
<p>격자의 크기 m, n과 물이 잠긴 지역의 좌표를 담은 2차원 배열 puddles이 매개변수로 주어집니다. <strong>오른쪽과 아래쪽으로만 움직여</strong> 집에서 학교까지 갈 수 있는 최단경로의 개수를 1,000,000,007로 나눈 나머지를 return 하도록 solution 함수를 작성해주세요.</p>
<h5 id="제한사항">제한사항</h5>
<ul>
<li>격자의 크기 m, n은 1 이상 100 이하인 자연수입니다.<ul>
<li>m과 n이 모두 1인 경우는 입력으로 주어지지 않습니다.</li>
</ul>
</li>
<li>물에 잠긴 지역은 0개 이상 10개 이하입니다.</li>
<li>집과 학교가 물에 잠긴 경우는 입력으로 주어지지 않습니다.</li>
</ul>
<h5 id="입출력-예">입출력 예</h5>
<table>
<thead>
<tr>
<th>m</th>
<th>n</th>
<th>puddles</th>
<th>return</th>
</tr>
</thead>
<tbody><tr>
<td>4</td>
<td>3</td>
<td>[[2, 2]]</td>
<td>4</td>
</tr>
</tbody></table>
<h5 id="입출력-예-설명">입출력 예 설명</h5>
<p><img src="https://grepp-programmers.s3.amazonaws.com/files/ybm/32c67958d5/729216f3-f305-4ad1-b3b0-04c2ba0b379a.png" alt="image1.png"></p>
<h2 id="문제-풀이">문제 풀이</h2>
<hr>
<p>문제 풀이는 아래의 그림과 같다</p>
<img width="768" alt="image-20220327221305363" src="https://user-images.githubusercontent.com/44612896/160283553-00390941-aee5-4128-96f3-063380a92fdc.png" style="zoom:50%;" >



<ol>
<li><code>map[i][1] = 1</code>로 초기화 시킨다.</li>
<li><code>map[1][i] = 1</code>로 초기화 시킨다.,</li>
<li><code>map[i][j] = map[i-1][j] + ma[i][j-1]</code> 를 하면 아래의 그림과 같이 나타낼 수 있다.</li>
</ol>
<img width="787" alt="image-20220327221435064" src="https://user-images.githubusercontent.com/44612896/160283551-21daa63d-a069-4d8f-842c-2978113dfe70.png" style="zoom:50%;" >



<h3 id="예외-처리"><code>예외 처리</code></h3>
<ol>
<li><code>map[1][i], map[i][1]에 연못이 있는 경우에는 그 연못부터 끝까지 0처리를 해줘야 한다</code></li>
<li><code>map[i][j]</code>에 연못이 있는 경우에는 그 부분만 0로 만들어 주면된다!</li>
<li>1_000_000_007을 넘어가는 경우가 있을 수 있기 때문에 <code>map[i][j] = ((map[i-1][j] % DIV ) + (map[i][j-1] % DIV)) % DIV</code> 하면 된다</li>
</ol>
<p><code>예시</code> 아래의 그림과 같다.</p>
<img width="795" alt="image-20220327221929485" src="https://user-images.githubusercontent.com/44612896/160283548-a8d1b07f-00e1-4512-b419-9ef5eb3e17bf.png" style="zoom:50%;" >



<pre><code class="language-java">class Solution {
    public int solution(int m, int n, int[][] puddles) {
        final int DIV = 1_000_000_007;

        // m, n이 주어진다 m : col n : row;

        int[][] map = new int[n + 1][m + 1];

        for (int i = 1 ; i &lt;= n ; i++){
            Arrays.fill(map[i], Integer.MAX_VALUE);
        }

        // 초기화
        for (int i = 1 ; i &lt;= n ; i++) map[i][1] = 1;
        for (int j = 1 ; j &lt;= m ; j++) map[1][j] = 1;



        //puddles m , n
        int row, col;
        for (int[] puddle : puddles){
            col = puddle[0];
            row = puddle[1];

            if (row == 1){
                for (int i = col ; i &lt;= m ; i++){
                    map[row][i] = 0;
                }
            }else if(col == 1){
                for (int i = row ; i &lt;= n ; i++){
                    map[i][col] = 0;
                }
            }else{
                map[row][col] = 0;
            }
        }

        for (int i = 2 ; i &lt;= n ; i++){
            for (int j = 2 ; j &lt;= m ; j++){
                if (map[i][j] == 0) continue;
                map[i][j] = ((map[i - 1][j] % DIV) + (map[i][j - 1] % DIV)) % DIV;
            }
        }


        return map[n][m];
    }
}</code></pre>
]]></description>
        </item>
    </channel>
</rss>