<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>camel-man-ims.log</title>
        <link>https://velog.io/</link>
        <description>티스토리로 이사했습니다! https://imsfromseoul.tistory.com/ + https://camel-man-ims.tistory.com/</description>
        <lastBuildDate>Sun, 18 Jul 2021 13:07:30 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>camel-man-ims.log</title>
            <url>https://images.velog.io/images/camel-man-ims/profile/3178d48c-dd99-422f-bded-3a776c93d56b/KakaoTalk_20200910_150526309.jpg</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. camel-man-ims.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/camel-man-ims" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[프로그래머스 # stack & queue - 기능개발]]></title>
            <link>https://velog.io/@camel-man-ims/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-stack-queue-%EA%B8%B0%EB%8A%A5%EA%B0%9C%EB%B0%9C</link>
            <guid>https://velog.io/@camel-man-ims/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-stack-queue-%EA%B8%B0%EB%8A%A5%EA%B0%9C%EB%B0%9C</guid>
            <pubDate>Sun, 18 Jul 2021 13:07:30 GMT</pubDate>
            <description><![CDATA[<h1 id="🏆-해결">🏆 해결</h1>
<p>걸린시간 : 25분
문제 난이도 : 하
주석 : 코드를 짜고 한 번에 통과가 돼서 신기했다.
역시 코드를 짜기 전에 코드 검증시간이 길어야 한다.</p>
<h1 id="📌-문제">📌 문제</h1>
<pre><code>progress = [90,95,98,1]
speeds = [1,5,1,99]</code></pre><p>이런식으로 progress 와 speeds 배열이 주어진다.</p>
<p>각 speeds는 각 progress가 진행되는 속도를 의미한다.</p>
<p>100이 되면 해당 progress가 완료되는 것인데, 순서상 뒤의 것은 앞의 것이 완료될 때까지 배포되지 못한다.</p>
<p>위의 예에서는 return value가</p>
<pre><code>[2,2]</code></pre><p>가 나와야 한다.</p>
<h1 id="🔥-아이디어">🔥 아이디어</h1>
<p>progress에 speeds를 각 loop마다 더한다.</p>
<p><img src="https://images.velog.io/images/camel-man-ims/post/10a4a273-cf46-4b50-b497-13e20bb3c614/image.png" alt=""></p>
<p>해당 index가 100이 될 경우, </p>
<p>뒤에 100이 넘는 애들의 숫자를 세주고, 100이 안되는 놈으로 이동해준다.
만약 index가 loop의 길이를 넘는 경우 멈춘다.</p>
<h2 id="🎅-tip">🎅 TIP</h2>
<ol>
<li>전체 풀이에 대한 생각을 하고, 꽉 잡고 있는다.
(이 때, 예시와 귀납법을 적절히 사용한다)</li>
<li>시각화 한다.</li>
<li>sudo code로 검증한다.
( loop는 어떻게 돌 것인지, 1,2번에 해당하는 풀이로 적절히 가고 있는지 등 )</li>
<li>구현한다.</li>
</ol>
<h1 id="📋-코드">📋 코드</h1>
<pre><code class="language-python"># 21.07.18

def solution(progresses, speeds):
    index = 0
    length = len(progresses)

    result = []

    while index&lt;length:
        count = 1

        for i in range(length):
            progresses[i] += speeds[i]

        if progresses[index] &gt;=100:
            index +=1
            while index&lt;length and progresses[index]&gt;=100:
                index+=1
                count+=1

            result.append(count)
    return result


solution([95, 90, 99, 99, 80, 99],[1, 1, 1, 1, 1, 1])</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준📌18 (구현) - 설탕배달 # 2839번]]></title>
            <link>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%8018-%EA%B5%AC%ED%98%84-%EC%84%A4%ED%83%95%EB%B0%B0%EB%8B%AC-2839%EB%B2%88</link>
            <guid>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%8018-%EA%B5%AC%ED%98%84-%EC%84%A4%ED%83%95%EB%B0%B0%EB%8B%AC-2839%EB%B2%88</guid>
            <pubDate>Thu, 15 Jul 2021 06:50:08 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-문제">📌 문제</h1>
<p>n이 주어질 때, 5와 3을 빼서 0이 될 수 있는 지 확인한다.
5를 먼저 뺄 수 있을 때는 5를 뺀다. 5와 3을 뺀 횟수를 구하라.</p>
<h1 id="📌-풀이과정">📌 풀이과정</h1>
<p>나는 5을 먼저 빼고, 3이 남는 case를 생각해서 구하려고 했는데, 그러니까 상당히 복잡했다.</p>
<p>반대로, 3이 먼저 빠져서 5의 배수가 될 때까지 돌고, 5의 배수가 되지 않는다면 되지 않는 것이라 생각하면 쉽다.</p>
<p>아래 코드를 참조했다.</p>
<blockquote>
<p><a href="https://ooyoung.tistory.com/81">https://ooyoung.tistory.com/81</a></p>
</blockquote>
<h1 id="📌-코드">📌 코드</h1>
<pre><code class="language-python">import sys

n = int(input())

count = 0

while n&gt;=0:
    if n%5==0:
        count += n//5
        print(count)
        sys.exit(0)
    n-=3
    count+=1

print(-1)
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 #17 (구현) - 부녀회장이 될테야]]></title>
            <link>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-17-%EA%B5%AC%ED%98%84-%EB%B6%80%EB%85%80%ED%9A%8C%EC%9E%A5%EC%9D%B4-%EB%90%A0%ED%85%8C%EC%95%BC</link>
            <guid>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-17-%EA%B5%AC%ED%98%84-%EB%B6%80%EB%85%80%ED%9A%8C%EC%9E%A5%EC%9D%B4-%EB%90%A0%ED%85%8C%EC%95%BC</guid>
            <pubDate>Wed, 14 Jul 2021 07:06:24 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-문제">📌 문제</h1>
<p><img src="https://images.velog.io/images/camel-man-ims/post/3b87639a-8fd1-470a-8010-cd6a15ffae77/KakaoTalk_20210714_160311344.png" alt=""></p>
<p>i층 j호는</p>
<p>i-1층부터 j호까지 더한 값이다.</p>
<p>0층 k호의 값은 k이다.</p>
<h1 id="📌-아이디어">📌 아이디어</h1>
<p>k,n 값이 14보다 작으므로, 완전탐색을 한다.</p>
<p>즉, arr 값을 모두 완성시켜놓고 후에 탐색을 진행한다.</p>
<h1 id="📌-코드">📌 코드</h1>
<pre><code class="language-python">n = int(input())

arr =[[0]*14 for _ in range(15)]

for i in range(14):
    arr[0][i] = i+1

for i in range(1,15):
    for j in range(0,14):

        sum_result = 0

        for k in range(0,j+1):
            sum_result += arr[i-1][k]

        arr[i][j] = sum_result


for _ in range(n):
    K = int(input())
    N = int(input())

    print(arr[K][N-1])
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 #16 (구현) - ACM 호텔]]></title>
            <link>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-16-%EA%B5%AC%ED%98%84-ACM-%ED%98%B8%ED%85%94</link>
            <guid>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-16-%EA%B5%AC%ED%98%84-ACM-%ED%98%B8%ED%85%94</guid>
            <pubDate>Mon, 12 Jul 2021 11:13:27 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-문제">📌 문제</h1>
<p>문제가 뭔가 길고 거창한 것 같지만, 실은 굉장히 간단하다.</p>
<p>6층 일경우, 위와 같이 101을 시작으로 층수가 높아진다.
만약 <code>current+100 &gt; H</code> 라면, <code>current = current - (H-1)*100 +1</code> 을 해준다.
아니라면, <code>current = current +100</code> 을 해준다.</p>
<pre><code>101 -&gt; 201
601 -&gt; 102
되는 과정을 생각해보면 단순하게 식을 유도할 수 있다.</code></pre><h1 id="📌-코드">📌 코드</h1>
<pre><code class="language-python">n=int(input())

for _ in range(n):
    H,W,N = map(int,input().split())

    current = 101
    count = 1

    while N!=count:
        if (current+100) // 100 &lt;= H:
            current+=100
            count+=1
        else:
            current = current - (H-1)*100 + 1
            count+=1

    print(current)</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 #15 (구현) - 분수찾기 1193번]]></title>
            <link>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-15-%EA%B5%AC%ED%98%84-%EB%B6%84%EC%88%98%EC%B0%BE%EA%B8%B0-1193%EB%B2%88</link>
            <guid>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-15-%EA%B5%AC%ED%98%84-%EB%B6%84%EC%88%98%EC%B0%BE%EA%B8%B0-1193%EB%B2%88</guid>
            <pubDate>Sat, 10 Jul 2021 16:19:37 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-문제">📌 문제</h1>
<p>지그재그로 분수가 주어질 때, 해당 순서의 분수를 찾는 문제</p>
<blockquote>
<p><a href="https://www.acmicpc.net/problem/1193">https://www.acmicpc.net/problem/1193</a></p>
</blockquote>
<h1 id="📌-사고과정">📌 사고과정</h1>
<h2 id="🔥-실수">🔥 실수</h2>
<p>처음에는 </p>
<p><img src="https://images.velog.io/images/camel-man-ims/post/a422251a-2537-496d-8566-664859446a4b/image.png" alt=""></p>
<p>이런식의 지그재그라고 생각했었다.</p>
<p><img src="https://images.velog.io/images/camel-man-ims/post/bd9041bf-6386-41e6-9552-88c258326979/image.png" alt=""></p>
<p>허나 문제를 다시 읽어보니 ( 코드를 제출하고 나서, 틀리고나서 다시 확인해보니 )
위와 같은 지그재그였다.</p>
<p>문제를 똑바로 읽는 것이 정말 중요하다.</p>
<h2 id="🔥-아이디어">🔥 아이디어</h2>
<p>지그재그는 두 방법으로 이루어진다.</p>
<p><img src="https://images.velog.io/images/camel-man-ims/post/fecabb37-b6da-41b5-aac3-774dbb754072/image.png" alt=""></p>
<ol>
<li>아래로 내려갔다면, 분모가 1일때까지 내려간다.</li>
<li>방향이 아래였던 상태에서 분모가 1이라면, 분자에 +1을 한다.</li>
<li>방향을 위로 바꾼다.</li>
</ol>
<p><img src="https://images.velog.io/images/camel-man-ims/post/12c65ea0-43f6-4a51-887f-caac002cf81f/image.png" alt=""></p>
<p>위로 올라갈 때도 로직은 똑같다. 방향만 다를 뿐이다.</p>
<ol>
<li>위로 올라갔다면, 분자가 1일때까지 올라간다.</li>
<li>분자가 1이라면 분모에 1을 더해준다.</li>
<li>방향을 아래로 바꾼다.</li>
</ol>
<p>그렇다면 방향을 알려줄 변수가 필요하다.
나는 flag로 방향을 설정했다.</p>
<p>만약 <code>flag == True</code> 이면 방향을 아래로, <code>flag == False</code> 라면 방향을 위로 설정했다.</p>
<h2 id="🔥-주의점">🔥 주의점</h2>
<p><code>while count!=n :</code> 조건으로 while loop를 돌릴 건데, while loop안에 다시 while loop가 돌으므로 중간 조건으로 <code>count!=n</code>을 넣어주어야 한다.</p>
<h1 id="📌-코드">📌 코드</h1>
<pre><code class="language-python">import sys

n = int(input())

if n==1:
    print(&quot;1/1&quot;)
    sys.exit(0)

son = 1
mom = 2
count = 2

# flag
# True = down
# False = up
flag = True

while count!=n:
    if flag:
        while mom!=1 and count!=n:
            son+=1
            mom-=1
            count+=1
        if count==n:
            break
        else:
            son+=1
            count+=1
            flag=False
    else:
        while son!=1 and count!=n:
            son-=1
            mom+=1
            count+=1
        if count==n:
            break
        else:
            mom+=1
            count+=1
            flag=True
print(str(son) + &quot;/&quot; + str(mom))</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 #13,14 (구현) - 평균, 평균은 넘겠지]]></title>
            <link>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-13-%EA%B5%AC%ED%98%84-%ED%8F%89%EA%B7%A0</link>
            <guid>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-13-%EA%B5%AC%ED%98%84-%ED%8F%89%EA%B7%A0</guid>
            <pubDate>Sun, 27 Jun 2021 11:11:38 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-평균---문제">📌 평균 - 문제</h1>
<p>평균과 올림값을 구하는 문제</p>
<blockquote>
<p><a href="https://www.acmicpc.net/problem/1546">https://www.acmicpc.net/problem/1546</a></p>
</blockquote>
<h1 id="📌-아이디어">📌 아이디어</h1>
<p>반올림 = <code>round</code> 함수 이용</p>
<p>평균 = <code>sum(arr)/len(arr)</code></p>
<h1 id="📌-코드">📌 코드</h1>
<pre><code class="language-python">n = int(input())

arr = list(map(int,input().split()))

max_value = max(arr)

fixed_arr = []

for i in arr:
    temp = i/max_value * 100
    fixed_arr.append(round(temp,2))

print(round(sum(fixed_arr)/len(arr),2))</code></pre>
<h1 id="📌-평균은-넘겠지---문제">📌 평균은 넘겠지 - 문제</h1>
<p>이번에는 소수점 밑에 자리가 있든 없든 3자리까지 출력하는 문제</p>
<h1 id="📌-아이디어-1">📌 아이디어</h1>
<p>format 이용</p>
<pre><code class="language-python">print(&quot;{:.10f}%&quot;.format(40.7777))
# 40.7777000000%</code></pre>
<p>format 함수를 이용하면, 값이 있든 없든 원하는 숫자까지 출력할 수 있다.</p>
<h1 id="📌-코드-1">📌 코드</h1>
<pre><code class="language-python">n= int(input())

array = []

for _ in range(n):
    input_arr = list(map(int,input().split()))
    arr = []
    for i in range(1,len(input_arr)):
        arr.append(input_arr[i])

    average = sum(arr)/len(arr)
    result = 0
    for i in arr:
        if i&gt;average:
            result+=1
    array.append(result/len(arr))

for i in array:
    i= i*100
    print(&quot;{:.3f}%&quot;.format(i))</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 #12 (구현) - 그룹 단어 체커]]></title>
            <link>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-12-%EA%B5%AC%ED%98%84-%EA%B7%B8%EB%A3%B9-%EB%8B%A8%EC%96%B4-%EC%B2%B4%EC%BB%A4</link>
            <guid>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-12-%EA%B5%AC%ED%98%84-%EA%B7%B8%EB%A3%B9-%EB%8B%A8%EC%96%B4-%EC%B2%B4%EC%BB%A4</guid>
            <pubDate>Sat, 26 Jun 2021 03:22:37 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-문제">📌 문제</h1>
<p>문자열을 순회했을 때, 해당 문자가 전에 나온 문자가 아닌 문자열의 갯수를 구하라.
( 단, 같은 문자가 연속적으로 나왔을 때는 전에 나온 문자로 치지 않는다 )</p>
<p>ex)</p>
<pre><code>aaabbaaccc (x)
aabbbcc (o)</code></pre><h1 id="📌-아이디어">📌 아이디어</h1>
<p>문자열을 돌면서 해당 문자를 <code>set</code> 에 저장한다.
만약 해당 문자가 <code>set</code>에 값이 있을 때,</p>
<ol>
<li>전의 값과 값이 동일하다면 현재 연속적이라는 의미이므로 통과다.</li>
<li>만약 전의 값과 값이 동일하지 않다면 이미 나왔던 문자라는 뜻이므로 통과를 하지 못하고 종료해준다.</li>
</ol>
<p>만약 <code>set</code>에 값이 없다면 추가해준다.</p>
<h2 id="🔥-실수">🔥 실수</h2>
<p>🤡 1. <code>s[i]</code></p>
<pre><code class="language-python">if s[i] not in hash_set:
# 을 해야 하는데
if s not in hash_set:
# 을 해버렸다.</code></pre>
<p>🤡 2. <code>not in</code></p>
<pre><code class="language-python">if s[i] not in~
# 이렇게 해야 하는데
if not s[i] in ~
# 이렇게 헷갈렸다.</code></pre>
<h1 id="📌-코드">📌 코드</h1>
<pre><code class="language-python">n = int(input())

result = 0

for _ in range(n):
    s = input()
    hash_set = set()
    flag = True
    for i in range(len(s)):
        if s[i] not in hash_set:
            hash_set.add(s[i])
            i += 1
        elif s[i] in hash_set:
            if s[i-1] == s[i]:
                i+=1
            elif s[i-1] != s[i]:
                flag=False
                break
    if flag:
        result+=1

print(result)</code></pre>
<h1 id="📌-다른-사람-풀이">📌 다른 사람 풀이</h1>
<p>slicing을 이용해서 더 간편하게 풀이한 것 같다.</p>
<p>일치하지 않을 때, 뒤의 문자안에 있다면 빼준다.</p>
<pre><code class="language-python">n=int(input())
cnt=0
for _ in range(n):
    word=input()
    for i in range(len(word)-1):
        if word[i]!=word[i+1]:
            if word[i] in word[i+1:]:
                n-=1
                break
print(n)</code></pre>
<blockquote>
<p><a href="https://velog.io/@wjdtmdgml/%EB%B0%B1%EC%A4%80%EA%B7%B8%EB%A3%B9-%EB%8B%A8%EC%96%B4-%EC%B2%B4%EC%BB%A41316%EB%B2%88Python%ED%8C%8C%EC%9D%B4%EC%8D%AC%EA%B5%AC%ED%98%84%EB%AC%B8%EC%9E%90%EC%97%B4">https://velog.io/@wjdtmdgml/%EB%B0%B1%EC%A4%80%EA%B7%B8%EB%A3%B9-%EB%8B%A8%EC%96%B4-%EC%B2%B4%EC%BB%A41316%EB%B2%88Python%ED%8C%8C%EC%9D%B4%EC%8D%AC%EA%B5%AC%ED%98%84%EB%AC%B8%EC%9E%90%EC%97%B4</a></p>
</blockquote>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 #11 (구현) - 크로아티아 알파벳]]></title>
            <link>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-11-%EA%B5%AC%ED%98%84-%ED%81%AC%EB%A1%9C%EC%95%84%ED%8B%B0%EC%95%84-%EC%95%8C%ED%8C%8C%EB%B2%B3</link>
            <guid>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-11-%EA%B5%AC%ED%98%84-%ED%81%AC%EB%A1%9C%EC%95%84%ED%8B%B0%EC%95%84-%EC%95%8C%ED%8C%8C%EB%B2%B3</guid>
            <pubDate>Sat, 26 Jun 2021 02:56:53 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-문제">📌 문제</h1>
<p>입력값이 주어졌을 때, 입력 값안에 해당 문자열에 해당하는 갯수가 얼마나 있는가 세는 문제</p>
<blockquote>
<p><a href="https://www.acmicpc.net/problem/2941">https://www.acmicpc.net/problem/2941</a></p>
</blockquote>
<h1 id="📌-아이디어">📌 아이디어</h1>
<p>해당 문자열을 <code>set</code>안에 넣고 loop를 돌면서 <code>set</code>에 해당하는 문자가 있는지 확인했다.</p>
<h2 id="🔥-실수">🔥 실수</h2>
<p>문제를 똑바로 읽지 않아서 해당 문자열에 해당 하지 않을 때는 +1을 해주라는 것을 구현하지 않았었다.</p>
<h1 id="📌-코드">📌 코드</h1>
<pre><code class="language-python">s_input = input()

i=0

hash_set = set()

hash_set.add(&quot;c=&quot;)
hash_set.add(&quot;c-&quot;)
hash_set.add(&quot;dz=&quot;)
hash_set.add(&quot;d-&quot;)
hash_set.add(&quot;lj&quot;)
hash_set.add(&quot;nj&quot;)
hash_set.add(&quot;s=&quot;)
hash_set.add(&quot;z=&quot;)

count =0

while i&lt;len(s_input):
    word_three = s_input[i:i+3]
    word_two = s_input[i:i+2]

    if word_two in hash_set:
        i = i+2
        count +=1
    elif word_three in hash_set:
        i = i+3
        count +=1
    else:
        i = i+1
        count +=1

print(count)</code></pre>
<h1 id="📌-다른-사람-풀이">📌 다른 사람 풀이</h1>
<p>해당 문자열을 list로 선언해놓고, 해당 문자열에 해당 하는 값을 하나의 문자로 바꾸어준다. 그러고 총 길이를 세면 원하는 값이 나온다.</p>
<pre><code class="language-python">a = [&#39;c=&#39;, &#39;c-&#39;, &#39;dz=&#39;, &#39;d-&#39;, &#39;lj&#39;, &#39;nj&#39;, &#39;s=&#39;, &#39;z=&#39;]
alpha = input()

for t in a:
    alpha = alpha.replace(t, &#39;*&#39;)
    print(alpha)

print(len(alpha))</code></pre>
<blockquote>
<p><a href="https://hongku.tistory.com/255">https://hongku.tistory.com/255</a></p>
</blockquote>
]]></description>
        </item>
        <item>
            <title><![CDATA[LinkedList 중복된 값 제거]]></title>
            <link>https://velog.io/@camel-man-ims/LinkedList-%EC%A4%91%EB%B3%B5%EB%90%9C-%EA%B0%92-%EC%A0%9C%EA%B1%B0</link>
            <guid>https://velog.io/@camel-man-ims/LinkedList-%EC%A4%91%EB%B3%B5%EB%90%9C-%EA%B0%92-%EC%A0%9C%EA%B1%B0</guid>
            <pubDate>Fri, 25 Jun 2021 12:33:46 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-출처">📌 출처</h1>
<blockquote>
<p>엔지니어 대한민국
<a href="https://www.youtube.com/watch?v=Ce4baygLMz0">https://www.youtube.com/watch?v=Ce4baygLMz0</a></p>
</blockquote>
<h1 id="📌-두가지-방법">📌 두가지 방법</h1>
<h2 id="🔥-set-이용">🔥 Set 이용</h2>
<p><img src="https://images.velog.io/images/camel-man-ims/post/d014f7d2-1fd6-458d-9655-da6abe6f9042/image.png" alt=""></p>
<p><code>node.next</code>의 값이 <code>set</code>에 있을 경우, <code>node.next = node.next.next</code> 로 바꾸어준다.</p>
<p>값이 없을 시, <code>node</code>를 다음 값으로 이동하고, 해당 <code>node</code>의 값을 <code>set</code>에 넣어준다.</p>
<h3 id="🔥-코드">🔥 코드</h3>
<pre><code class="language-python">class Node:
    def __init__(self,val):
        self.val = val
        self.next = None

    def add(self,val):
        node = self
        while node.next is not None:
            node=node.next
        node.next = Node(val)
    def print(self):
        node = self
        while node:
            print(node.val)
            node=node.next

    def remove_duplicate(self):
        hash_set = set()
        node = self
        hash_set.add(node.val)
        while node is not None and node.next is not None:
            if node.next.val in hash_set:
                node.next = node.next.next
            else:
                node=node.next
                hash_set.add(node.val)


n1 = Node(1)
n1.add(2)
n1.add(3)
n1.add(3)
n1.add(4)
n1.add(4)
n1.add(4)
n1.add(4)
n1.add(5)

n1.remove_duplicate()
n1.print()</code></pre>
<h3 id="🤡-복잡도">🤡 복잡도</h3>
<p>시간복잡도 <code>O(n)</code>
공간복잡도 <code>O(n)</code></p>
<h2 id="🔥-러너-이용">🔥 러너 이용</h2>
<blockquote>
<p>따로 버퍼공간 ( 위의 예에서 <code>set</code> )을 이용하지 말고 풀어보라.</p>
</blockquote>
<p><img src="https://images.velog.io/images/camel-man-ims/post/2e042eed-e44e-4373-9859-7eefb9a45382/image.png" alt=""></p>
<p>해당 node를 순회하면서, 해당 node에 해당하는 runner를 둔다.</p>
<p><img src="https://images.velog.io/images/camel-man-ims/post/53084b8f-7efb-4181-9ec0-b5cdd6904bf8/image.png" alt=""></p>
<p><img src="https://images.velog.io/images/camel-man-ims/post/87b14b18-082c-4fe0-ac55-7e1663886066/image.png" alt=""></p>
<p>위 그림과 같이 node는 고정하면서, runner는 앞으로 나아가며, <code>node.val == runner.next.val</code> 검사를 한다.</p>
<p>위의 경우 해당하므로</p>
<p><img src="https://images.velog.io/images/camel-man-ims/post/89cee3b5-e53e-420d-a37b-ab11e7eac049/image.png" alt=""></p>
<p><code>runner.next = runner.next.next</code>로 만들어주고, runner를 전진시킨다.</p>
<h3 id="🔥-코드-1">🔥 코드</h3>
<pre><code class="language-python">class Node:
    def __init__(self,val):
        self.val = val
        self.next = None

    def add(self,val):
        node = self
        while node.next is not None:
            node=node.next
        node.next = Node(val)
    def print(self):
        node = self
        while node:
            print(node.val)
            node=node.next

    def remove_duplicate(self):
        node = self
        while node is not None and node.next is not None:
            runner = node
            while runner.next is not None :
                if node.val == runner.next.val:
                    runner.next =runner.next.next
                else:
                    runner=runner.next
            node=node.next

n1 = Node(1)
n1.add(2)
n1.add(3)
n1.add(3)
n1.add(4)
n1.add(4)
n1.add(4)
n1.add(4)
n1.add(5)

n1.remove_duplicate()
n1.print()
</code></pre>
<h3 id="🤡-복잡도-1">🤡 복잡도</h3>
<p>시간복잡도는 <code>O(n^2)</code> 이지만
공간복잡도는 <code>O(1)</code> 이다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[카카오 2021 #3 - 순위검색]]></title>
            <link>https://velog.io/@camel-man-ims/%EC%B9%B4%EC%B9%B4%EC%98%A4-2021-3-%EC%88%9C%EC%9C%84%EA%B2%80%EC%83%89</link>
            <guid>https://velog.io/@camel-man-ims/%EC%B9%B4%EC%B9%B4%EC%98%A4-2021-3-%EC%88%9C%EC%9C%84%EA%B2%80%EC%83%89</guid>
            <pubDate>Fri, 25 Jun 2021 07:18:12 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-문제">📌 문제</h1>
<p>해당 문자열에 맞는 값의 수 return 하기</p>
<p>단, 효율성 테스트가 있다.</p>
<blockquote>
<p><a href="https://programmers.co.kr/learn/courses/30/lessons/72412">https://programmers.co.kr/learn/courses/30/lessons/72412</a></p>
</blockquote>
<p>loop 2번 돌아서 확인하는 걸로는 풀리지 않는다.</p>
<p>일단 무지성으로 loop 2번 도는 걸로 풀었는데, 정확성은 통과했으나 효율성은 통과하지 못했다.</p>
<h1 id="📌-정확성만-통과한-풀이">📌 정확성만 통과한 풀이</h1>
<pre><code class="language-python">def solution(infos, query):

    result =[]

    for query_one in query:

        split_query = query_one.split(&quot; &quot;)
        split_query_no_and = []

        for s in split_query:
            if s != &quot;and&quot;:
                split_query_no_and.append(s)
        count = 0

        for info in infos:
            split_info = info.split(&quot; &quot;)

            if (split_query_no_and[0] == &#39;-&#39; or split_query_no_and[0] == split_info[0]) \
                    and (split_query_no_and[1] == &#39;-&#39; or split_query_no_and[1] == split_info[1]) \
                    and (split_query_no_and[2] == &#39;-&#39; or split_query_no_and[2] == split_info[2]) \
                    and (split_query_no_and[3] == &#39;-&#39; or split_query_no_and[3] == split_info[3]) \
                    and int(split_info[4]) &gt;= int(split_query_no_and[4]):
                count +=1
        result.append(count)

    return result

solution([&quot;java backend junior pizza 150&quot;,&quot;python frontend senior chicken 210&quot;,&quot;python frontend senior chicken 150&quot;,&quot;cpp backend senior pizza 260&quot;,&quot;java backend junior chicken 80&quot;,&quot;python backend senior chicken 50&quot;],[&quot;java and backend and junior and pizza 100&quot;,&quot;python and frontend and senior and chicken 200&quot;,&quot;cpp and - and senior and pizza 250&quot;,&quot;- and backend and senior and - 150&quot;,&quot;- and - and - and chicken 100&quot;,&quot;- and - and - and - 150&quot;])</code></pre>
<h2 id="🔥-주의점">🔥 주의점</h2>
<pre><code class="language-python">int(split_info[4]) &gt;= int(split_query_no_and[4]):</code></pre>
<p>해당 type은 str 이므로, int로 변환해주어야 한다.</p>
<h2 id="📌-풀이참조">📌 풀이참조</h2>
<blockquote>
<p><a href="https://tech.kakao.com/2021/01/25/2021-kakao-recruitment-round-1/">https://tech.kakao.com/2021/01/25/2021-kakao-recruitment-round-1/</a></p>
</blockquote>
]]></description>
        </item>
        <item>
            <title><![CDATA[카카오 2021 #2 - 메뉴 리뉴얼]]></title>
            <link>https://velog.io/@camel-man-ims/%EC%B9%B4%EC%B9%B4%EC%98%A4-2021-2-%EB%A9%94%EB%89%B4-%EB%A6%AC%EB%89%B4%EC%96%BC</link>
            <guid>https://velog.io/@camel-man-ims/%EC%B9%B4%EC%B9%B4%EC%98%A4-2021-2-%EB%A9%94%EB%89%B4-%EB%A6%AC%EB%89%B4%EC%96%BC</guid>
            <pubDate>Fri, 25 Jun 2021 05:40:51 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-문제">📌 문제</h1>
<p>손님이 시킨 메뉴가 있다. ex) A,B,D // B,C,D // A,B,D,E</p>
<p>메뉴 항목이 2명 이상의 손님한테 중복될 때, course 해당하는 메뉴의 최대값을 추출하려고 한다.</p>
<p>course = [2,3] 이라면 메뉴가 2개 중복된 메뉴 중 최대로 많이 중복된 메뉴 / 3개 중복된 메뉴 중 최대로 많이 중복된 메뉴를 추출하는 것이다.</p>
<p>위의 예에서는 2개 중복은 A,B 가 2회 // B,D가 3회, // A,D가 2회 // 나머지 항목은 모두 1회 이므로 <code>&quot;BD&quot;</code>를 결과에 추가한다.</p>
<p>3개 중복은 A,B,D가 유일하므로 <code>&quot;ABD&quot;</code>를 결과에 추가한다.</p>
<p>그래서 결과는 <code>[&quot;ABD&quot;,&quot;BD&quot;]</code> 이다. ( 사전순으로 정렬하라 )</p>
<blockquote>
<p><a href="https://programmers.co.kr/learn/courses/30/lessons/72411">https://programmers.co.kr/learn/courses/30/lessons/72411</a></p>
</blockquote>
<h1 id="📌-아이디어--풀이">📌 아이디어 &amp; 풀이</h1>
<pre><code>예시값
solution([&quot;XYZ&quot;, &quot;XWY&quot;, &quot;WXA&quot;],[2,3,4])</code></pre><h3 id="🔥-1">🔥 1.</h3>
<p>각 경우의 수를 모두 센다? -&gt; combination </p>
<h3 id="🔥-2">🔥 2.</h3>
<p>해당 값에 key에 대한 value를 추출한다? -&gt; map</p>
<pre><code class="language-python">def convert(s):
    result = &quot;&quot;
    for x in s:
        result +=x
    return result

def solution(orders, course):
    hash_map = dict()
    s_arr = []

    for order in orders:
        for num in course:
            c_arr = list(combinations(order,num))
            for c in c_arr:
                s_arr.append(convert(c))</code></pre>
<pre><code>s_arr 결과값
[&#39;XY&#39;, &#39;XZ&#39;, &#39;YZ&#39;, &#39;XYZ&#39;, &#39;XW&#39;, &#39;XY&#39;, &#39;WY&#39;, &#39;XWY&#39;, &#39;WX&#39;, &#39;WA&#39;, &#39;XA&#39;, &#39;WXA&#39;]</code></pre><h3 id="🔥-3">🔥 3.</h3>
<p>Combination을 하면 XY와 YX가 다르게 집계가 된다. 그래서 hash_map의 key값을 확인하기 전에, 정렬 후 넣어주어야 한다. </p>
<pre><code class="language-python">for s in s_arr:
    temp_arr = []
    for t in s:
        temp_arr.append(t)
    temp_arr.sort()
    sub_s = &quot;&quot;

    for t in temp_arr:
        sub_s += t

    if sub_s in hash_map:
        hash_map[sub_s]+=1
    else:
        hash_map[sub_s]=1</code></pre>
<pre><code>hash_map 값
{&#39;XY&#39;: 2, &#39;XZ&#39;: 1, &#39;YZ&#39;: 1, &#39;XYZ&#39;: 1, &#39;WX&#39;: 2, &#39;WY&#39;: 1, &#39;WXY&#39;: 1, &#39;AW&#39;: 1, &#39;AX&#39;: 1, &#39;AWX&#39;: 1}</code></pre><h3 id="🔥-4">🔥 4.</h3>
<p>각 길이에 따른 최대값을 추출한다.</p>
<pre><code class="language-python">for num in course:
    max_value = 0
    for s in hash_map:
        if len(s)==num:
            max_value = max(max_value,hash_map[s])
    for s in hash_map:
        if hash_map[s]==max_value and len(s)==num and hash_map[s]&gt;=2:
            result.append(s)
result.sort()
return result</code></pre>
<h1 id="📌-실수">📌 실수</h1>
<h3 id="🔥-1-1">🔥 1.</h3>
<p>만약 2개에 해당하는 메뉴를 추출한다고 하면 조합을 이용해서 구해야 하는데, 잘못 생각해서</p>
<pre><code class="language-python">for num in orders:
    for i in range(len(arr)-1):
        arr[i:i+num] # --&gt; 추출된 단어</code></pre>
<p>위와 같이 생각했다.</p>
<h1 id="📌-코드">📌 코드</h1>
<pre><code class="language-python">from itertools import combinations


def convert(s):
    result = &quot;&quot;
    for x in s:
        result +=x
    return result

def solution(orders, course):
    hash_map = dict()
    s_arr = []

    for order in orders:
        for num in course:
            c_arr = list(combinations(order,num))
            for c in c_arr:
                s_arr.append(convert(c))
    for s in s_arr:
        temp_arr = []
        for t in s:
            temp_arr.append(t)
        temp_arr.sort()
        sub_s = &quot;&quot;

        for t in temp_arr:
            sub_s += t

        if sub_s in hash_map:
            hash_map[sub_s]+=1
        else:
            hash_map[sub_s]=1

    result = []

    for num in course:
        max_value = 0
        for s in hash_map:
            if len(s)==num:
                max_value = max(max_value,hash_map[s])
        for s in hash_map:
            if hash_map[s]==max_value and len(s)==num and hash_map[s]&gt;=2:
                result.append(s)
    result.sort()
    return result</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[2차원 배열 90도 회전시키기]]></title>
            <link>https://velog.io/@camel-man-ims/2%EC%B0%A8%EC%9B%90-%EB%B0%B0%EC%97%B4-90%EB%8F%84-%ED%9A%8C%EC%A0%84%EC%8B%9C%ED%82%A4%EA%B8%B0</link>
            <guid>https://velog.io/@camel-man-ims/2%EC%B0%A8%EC%9B%90-%EB%B0%B0%EC%97%B4-90%EB%8F%84-%ED%9A%8C%EC%A0%84%EC%8B%9C%ED%82%A4%EA%B8%B0</guid>
            <pubDate>Thu, 24 Jun 2021 05:46:43 GMT</pubDate>
            <description><![CDATA[<p><img src="https://images.velog.io/images/camel-man-ims/post/cf8c33a4-c422-408d-b260-0c5ee3b4ee39/image.png" alt=""></p>
<h1 id="📌-규칙">📌 규칙</h1>
<p>1 2 3 4 가 바뀌는 경우를 생각해보자.</p>
<p>🔥 1. 
고정돼 있던 행이 ( 위의 예에서는 0 )
고정된 열로 바뀐다. ( 위의 예에서는 3 )</p>
<p>🔥 2.
각 열의 고정된 위치는 <code>arr.length-1-i</code> ( i = 행의 위치 ) 로 정해진다.</p>
<p>🔥 3.
증가분이 열에서 행으로 옮겨간다.</p>
<h1 id="📌-코드">📌 코드</h1>
<pre><code class="language-python">arr = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]

for nums in arr:
    print(nums)

result = [[0]*(len(arr)) for _ in range(len(arr))]

print(&quot;=======90도 회전 후========&quot;)

for i in range(len(arr)):
    for j in range(len(arr)):
        result[j][len(arr)-1-i]=arr[i][j]

for nums in result:
    print(nums)</code></pre>
<p><img src="https://images.velog.io/images/camel-man-ims/post/282b8393-c234-4532-a417-04855da26cff/image.png" alt=""></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[LeetCode #6 (node) - 팰린드롬 연결리스트]]></title>
            <link>https://velog.io/@camel-man-ims/LeetCode-6-node-%ED%8C%B0%EB%A6%B0%EB%93%9C%EB%A1%AC-%EC%97%B0%EA%B2%B0%EB%A6%AC%EC%8A%A4%ED%8A%B8</link>
            <guid>https://velog.io/@camel-man-ims/LeetCode-6-node-%ED%8C%B0%EB%A6%B0%EB%93%9C%EB%A1%AC-%EC%97%B0%EA%B2%B0%EB%A6%AC%EC%8A%A4%ED%8A%B8</guid>
            <pubDate>Thu, 24 Jun 2021 02:28:47 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-문제">📌 문제</h1>
<blockquote>
<p><a href="https://leetcode.com/problems/palindrome-linked-list/submissions/">https://leetcode.com/problems/palindrome-linked-list/submissions/</a></p>
</blockquote>
<p>주어진 linkedlist가 회문인지 판단하라.</p>
<h1 id="📌-아이디어">📌 아이디어</h1>
<p>deque에 담아놓고, <code>popleft()</code> 와 <code>pop()</code> 을 비교해서 일치하지 않으면 False, loop를 빠져나오면 True를 return</p>
<p>list로 선언해서 pop(0)와 pop()을 비교할 수도 있는데, list의 경우 pop(0)연산을 한 뒤 나머지 요소들을 재정렬하는데 O(n)이 걸리므로 deque를 이용해야 한다.
( 정렬후 요소들이 왼쪽으로 shifting된다 )</p>
<h1 id="📌-코드">📌 코드</h1>
<pre><code class="language-python"># https://leetcode.com/problems/palindrome-linked-list/
from collections import deque


class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

class Solution:
    def isPalindrome(self, head: ListNode) -&gt; bool:
        q = deque()
        node = head
        while node:
            q.append(node.val)
            node=node.next
        while len(q)&gt;1:
            if q.popleft() != q.pop():
                return False
        return True</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[카카오 2021 #1 - 신규아이디 추천]]></title>
            <link>https://velog.io/@camel-man-ims/%EC%B9%B4%EC%B9%B4%EC%98%A4-2021-1-%EC%8B%A0%EA%B7%9C%EC%95%84%EC%9D%B4%EB%94%94-%EC%B6%94%EC%B2%9C</link>
            <guid>https://velog.io/@camel-man-ims/%EC%B9%B4%EC%B9%B4%EC%98%A4-2021-1-%EC%8B%A0%EA%B7%9C%EC%95%84%EC%9D%B4%EB%94%94-%EC%B6%94%EC%B2%9C</guid>
            <pubDate>Wed, 23 Jun 2021 05:45:00 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-문제">📌 문제</h1>
<ol>
<li>대문자 -&gt; 소문자</li>
<li>알파벳 소문자, 숫자, 빼기(-), 밑줄(_), 마침표(.)를 제외한 모든 문자를 제거</li>
<li>new_id에서 마침표(.)가 2번 이상 연속된 부분을 하나의 마침표(.)로 치환</li>
<li>new_id에서 마침표(.)가 처음이나 끝에 위치한다면 제거</li>
<li>new_id가 빈 문자열이라면, new_id에 &quot;a&quot;를 대입</li>
<li>new_id의 길이가 16자 이상이면, new_id의 첫 15개의 문자를 제외한 나머지 문자들을 모두 제거
( 제거 후 마침표(.)가 new_id의 끝에 위치한다면 끝에 위치한 마침표(.) 문자를 제거합니다. )</li>
<li>new_id의 길이가 2자 이하라면, new_id의 마지막 문자를 new_id의 길이가 3이 될 때까지 반복해서 끝에 붙입니다.</li>
</ol>
<h1 id="📌-아이디어--헤맸던-점">📌 아이디어 &amp; 헤맸던 점</h1>
<p>기본적인 아이디어는 순서대로 구현하면 된다.</p>
<h3 id="🔥-1-lower-는-새로운-문자열을-반환한다">🔥 1. lower() 는 새로운 문자열을 반환한다.</h3>
<pre><code class="language-python">a = &quot;wewADAdwqdqw&quot;

a.lower()

print(a) // wewADAdwqdqw</code></pre>
<pre><code class="language-python">a = &quot;wewADAdwqdqw&quot;

a = a.lower()

print(a) // wewadadwqdqw</code></pre>
<h3 id="🔥-2-가장-헤맸던-부분인데-lena-for-loop-안에서-해당-문자열의-길이를-바꾸면-lena역시-바뀐다">🔥 2. 가장 헤맸던 부분인데, <code>len(a) for loop</code> 안에서 해당 문자열의 길이를 바꾸면 len(a)역시 바뀐다.</h3>
<pre><code class="language-python">changed_id = &quot;.qdqw....&quot;

for i in range(len(changed_id) - 1):
    if changed_id[i] == &#39;.&#39; and changed_id[i + 1] == &#39;.&#39;:
        changed_id = changed_id[:i] + changed_id[i + 1:]
    else:
        changed_id = changed_id

print(changed_id)</code></pre>
<p>위 코드는 i를 순회하면서 i가 <code>.</code> 일때, i+1 도 <code>.</code> 이라면 slicing을 이용해서 changed_id 의 값을 갱신하는 코드이다.</p>
<p>그런데 위 코드는 에러가 난다.</p>
<pre><code class="language-python">changed_id = &quot;.qdqw....&quot;

for i in range(len(changed_id) - 1):
    print(&quot;len(changed_id) = &quot; + str(len(changed_id)))
    print(i)
    if changed_id[i] == &#39;.&#39; and changed_id[i + 1] == &#39;.&#39;:
        changed_id = changed_id[:i] + changed_id[i + 1:]
    else:
        changed_id = changed_id

print(changed_id)</code></pre>
<p>위와 같이 for loop 안에 print를 넣어보자.</p>
<p><img src="https://images.velog.io/images/camel-man-ims/post/a27e7743-7c61-45bb-a3f6-d3276e24d6cb/image.png" alt=""></p>
<p>for loop 안에서 해당 문자열의 길이가 바뀌어서, loop의 범위 또한 바뀌었다. 그래서 해당 문자열의 끝까지 loop가 돌게 되고, index out of range 에러가 생긴다.</p>
<h3 id="🔥-개선">🔥 개선</h3>
<pre><code class="language-python">index=0
while index&lt;len(changed_id):
    if index != len(changed_id)-1 and changed_id[index]==&#39;.&#39; and changed_id[index+1]==&#39;.&#39;:
        index+=1
    elif index != len(changed_id)-1 and changed_id[index]==&#39;.&#39; and changed_id[index+1]!=&#39;.&#39;:
        changed_three += &quot;.&quot;
        index+=1
    else:
        changed_three += changed_id[index]
        index+=1</code></pre>
<p>헷갈리지 않기 위해 changed_three 새로운 문자열을 생성했다.</p>
<p>for loop는 i를 새로 지정해도 정해진 대로 돌으므로, while loop를 이용했다.</p>
<ol>
<li><code>i, i+1 = &#39;.&#39;</code> 이라면 넘어가고</li>
<li><code>i==&#39;.&#39; and i+1 !=&#39;.&#39;</code> 이면 <code>.</code>를 추가해줬다.</li>
<li>그 외에는 그냥 문자열을 추가해주면 된다.</li>
</ol>
<h3 id="🔥-3-양쪽-제거">🔥 3. 양쪽 제거</h3>
<pre><code class="language-python">    if len(changed_three) &gt;= 2:
        while changed_three[0] == &#39;.&#39; or changed_three[len(changed_three) - 1] == &#39;.&#39;:
            if changed_three[0] == &#39;.&#39; and changed_three[len(changed_three) - 1] == &#39;.&#39;:
                changed_three = changed_three[1:len(changed_three) - 1]
            elif changed_three[0] == &#39;.&#39;:
                changed_three = changed_three[1:]
            elif changed_three[len(changed_three) - 1] == &#39;.&#39;:
                changed_three = changed_three[:len(changed_three) - 1]

    if changed_three == &quot;.&quot;:
        changed_three = &quot;&quot;</code></pre>
<p>길이가 2 이상일때만 유효하다.</p>
<h2 id="📌-전체코드">📌 전체코드</h2>
<pre><code class="language-python"># 3 &lt;= len &lt;= 15
# - _ . 알파벳 소문자, 숫자
# .는 처음과 끝 불가능. 연속사용 x

def solution(new_id):
    # 1번 소문자 변환
    new_id = new_id.lower()

    # 2번 알파벳 소문자, 숫자, -, _, . 제외한 문자 제거
    changed_id = &quot;&quot;

    for s in new_id:
        if s.isalpha() or s.isdigit() or s == &#39;-&#39; or s == &#39;_&#39; or s == &#39;.&#39;:
            changed_id += s

    changed_three = &quot;&quot;
    # 3-2) 2번 . 이상이면 제거
    # changed_id 가 변화하므로 len(changed_id) 역시 변화함
    # for i in range(len(changed_id) - 1):
    #     if changed_id[i] == &#39;.&#39; and changed_id[i + 1] == &#39;.&#39;:
    #         changed_three = changed_id[:i] + changed_id[i + 1:]
    #     else:
    #         changed_three = changed_id
    index=0
    while index&lt;len(changed_id):
        if index != len(changed_id)-1 and changed_id[index]==&#39;.&#39; and changed_id[index+1]==&#39;.&#39;:
            index+=1
        elif index != len(changed_id)-1 and changed_id[index]==&#39;.&#39; and changed_id[index+1]!=&#39;.&#39;:
            changed_three += &quot;.&quot;
            index+=1
        else:
            changed_three += changed_id[index]
            index+=1

    # 3번 . 2번이상 제거.  . 맨앞이나 맨 뒤면 제거
    # 3-1) 맨앞이나 맨뒤 . 면 제거
    if len(changed_three) &gt;= 2:
        while changed_three[0] == &#39;.&#39; or changed_three[len(changed_three) - 1] == &#39;.&#39;:
            if changed_three[0] == &#39;.&#39; and changed_three[len(changed_three) - 1] == &#39;.&#39;:
                changed_three = changed_three[1:len(changed_three) - 1]
            elif changed_three[0] == &#39;.&#39;:
                changed_three = changed_three[1:]
            elif changed_three[len(changed_three) - 1] == &#39;.&#39;:
                changed_three = changed_three[:len(changed_three) - 1]

    if changed_three == &quot;.&quot;:
        changed_three = &quot;&quot;

    if changed_three == &quot;&quot;:
        changed_three += &quot;a&quot;

    if len(changed_three) &gt;= 16:
        changed_three = changed_three[:15]

    while len(changed_three) &lt; 3:
        changed_three += changed_three[len(changed_three) - 1]

    while changed_three[len(changed_three)-1] == &#39;.&#39;:
        changed_three = changed_three[:len(changed_three)-1]

    # print(changed_three)
    return changed_three


solution(&quot;...!@BaT#*..y.abcdefghijklm.&quot;)
solution(&quot;=.=&quot;)
solution(&quot;aa&quot;)
solution(&quot;123_.def&quot;)
solution(&quot;=weew.q.q&quot;)
solution(&quot;bb...&quot;)</code></pre>
<h2 id="📌-다른-사람-코드">📌 다른 사람 코드</h2>
<pre><code class="language-python">def solution(new_id):
    answer = &#39;&#39;
    # 1
    new_id = new_id.lower()
    # 2
    for c in new_id:
        if c.isalpha() or c.isdigit() or c in [&#39;-&#39;, &#39;_&#39;, &#39;.&#39;]:
            answer += c
    # 3
    while &#39;..&#39; in answer:
        answer = answer.replace(&#39;..&#39;, &#39;.&#39;)
    # 4
    if answer[0] == &#39;.&#39;:
        answer = answer[1:] if len(answer) &gt; 1 else &#39;.&#39;
    if answer[-1] == &#39;.&#39;:
        answer = answer[:-1]
    # 5
    if answer == &#39;&#39;:
        answer = &#39;a&#39;
    # 6
    if len(answer) &gt; 15:
        answer = answer[:15]
        if answer[-1] == &#39;.&#39;:
            answer = answer[:-1]
    # 7
    while len(answer) &lt; 3:
        answer += answer[-1]
    return answer</code></pre>
<ol>
<li><p>replace를 쓸 생각을 못했다.</p>
</li>
<li><p>slicing을 더 잘 이용하자.</p>
</li>
</ol>
]]></description>
        </item>
        <item>
            <title><![CDATA[LeetCode #5 (구현) - 주식가격]]></title>
            <link>https://velog.io/@camel-man-ims/LeetCode-5-%EA%B5%AC%ED%98%84-%EC%A3%BC%EC%8B%9D%EA%B0%80%EA%B2%A9</link>
            <guid>https://velog.io/@camel-man-ims/LeetCode-5-%EA%B5%AC%ED%98%84-%EC%A3%BC%EC%8B%9D%EA%B0%80%EA%B2%A9</guid>
            <pubDate>Wed, 23 Jun 2021 02:27:50 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-문제">📌 문제</h1>
<p><img src="https://images.velog.io/images/camel-man-ims/post/a66166c2-5448-47a3-bf93-1ae0f62fb41d/image.png" alt=""></p>
<p>위와 같이 주식가격이 변할 때, 가장 큰 이익을 낼 수 있는 값을 구하라.</p>
<blockquote>
<p><a href="https://leetcode.com/problems/best-time-to-buy-and-sell-stock">https://leetcode.com/problems/best-time-to-buy-and-sell-stock</a></p>
</blockquote>
<h1 id="📌-아이디어">📌 아이디어</h1>
<p>단순히 최대값과 최소값만 찾으면 되는거 아닌가? 라고 간단하게 생각할 수 있다. 그러나 위 문제는 index가 시간을 나타내기 떄문에 단순 최소 최대구하는 것으로 문제를 풀 수 없다.</p>
<p>위의 그림에서도 배열의 최소값과 저점매수 지점이 일치하지 않는 것을 알 수 있다.</p>
<p>즉, 주식가격이 시간에 따라 앞으로 나아가는 형태이므로</p>
<p>( 전의 최대값에서 앞의 최소값을 뺄 수 없다 )</p>
<ol>
<li><p>최소값의 갱신</p>
</li>
<li><p>최대-최소의 차이 갱신</p>
</li>
</ol>
<p>두가지를 해주어야 한다.</p>
<pre><code class="language-python">profit = 0
min_value = 9999999 ( sys.maximize )

for i in arr:
    min_value = min(min_value,i)
    profit = max(profit, i - min_value )</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[LeetCode #4 (구현) - 3sum]]></title>
            <link>https://velog.io/@camel-man-ims/LeetCode-4-%EA%B5%AC%ED%98%84-3sum</link>
            <guid>https://velog.io/@camel-man-ims/LeetCode-4-%EA%B5%AC%ED%98%84-3sum</guid>
            <pubDate>Tue, 22 Jun 2021 01:55:02 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-문제">📌 문제</h1>
<blockquote>
<p>3sum
<a href="https://leetcode.com/problems/3sum/">https://leetcode.com/problems/3sum/</a></p>
</blockquote>
<pre><code>Input: nums = [-1,0,1,2,-1,-4]
Output: [[-1,-1,2],[-1,0,1]]</code></pre><p>세 수의 합이 0이 되는 값 3개를 반환하라.</p>
<h1 id="📌-아이디어">📌 아이디어</h1>
<p>brute force로는 <code>O(n^3)</code> 이 나올 수 있지만, <code>O(n^2)</code>으로 푸는 것이 목표.</p>
<p>두 가지 풀이법이 있을 수 있다.</p>
<ol>
<li>two pointer 사용</li>
<li>i 순회 + 2sum 사용</li>
</ol>
<h2 id="🔥-2pointer">🔥 2pointer</h2>
<p><img src="https://images.velog.io/images/camel-man-ims/post/8e34a9a2-849c-47c2-828a-1ffd2c27354c/image.png" alt=""></p>
<p>배열을 정렬하고, i를 순회한다.</p>
<pre><code class="language-python">for i in range(len(arr)-2):
    if i&gt;0 and arr[i] == arr[i-1]:
        continue
# 중복값 제거</code></pre>
<p>배열이 정렬 돼 있으므로, 세 수의 합인 sum이 0보다 크다면 right --, 0보다 작다면 left ++ 을 해준다.</p>
<pre><code class="language-python">    left = i+1
    right = len(arr)-1

    while left&lt;right:
        sum = arr[i] + arr[left] + arr[right]
        if sum &lt; 0:
            left +=1
        elif sum &gt; 0 :
            right -= 1
        else:
            result.append(arr[i],arr[left],arr[right])</code></pre>
<p>중복된 값이 있을 수 있으므로, 중복된 값을 제거한다.</p>
<pre><code class="language-python">    while left&lt;right and arr[left] == arr[left+1]:
        left+=1
    while left&lt;right and arr[right] == arr[right-1]:
        right-=1</code></pre>
<h2 id="🔥-i--2sum-이용">🔥 i + 2sum 이용</h2>
]]></description>
        </item>
        <item>
            <title><![CDATA[LeetCode #3 (구현) - 빗물 트래핑]]></title>
            <link>https://velog.io/@camel-man-ims/LeetCode-3-%EA%B5%AC%ED%98%84-%EB%B9%97%EB%AC%BC-%ED%8A%B8%EB%9E%98%ED%95%91</link>
            <guid>https://velog.io/@camel-man-ims/LeetCode-3-%EA%B5%AC%ED%98%84-%EB%B9%97%EB%AC%BC-%ED%8A%B8%EB%9E%98%ED%95%91</guid>
            <pubDate>Tue, 22 Jun 2021 00:37:54 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>Trapping Rain Water
<a href="https://leetcode.com/problems/trapping-rain-water/">https://leetcode.com/problems/trapping-rain-water/</a></p>
</blockquote>
<h1 id="📌-문제">📌 문제</h1>
<p><img src="https://images.velog.io/images/camel-man-ims/post/1bf19815-4e47-493c-a51d-5a3e2afeed90/image.png" alt=""></p>
<p>위와 같이 기둥들이 있을 때, 빗물이 고이는 volume의 수를 세라.</p>
<p>( volume = 기둥 높이의 차이만큼 생긴다 )</p>
<h1 id="📌-아이디어">📌 아이디어</h1>
<p>max 값을 기준으로 왼쪽과 오른쪽이 나뉜다.
max 값을 향해 왼쪽과 오른쪽이 전진하는데, ( two poniter )
이 때 left 기준으로</p>
<pre><code>left_max = max(left_max,heights[left])
left_max - heights[left] 의 값을 volume에 더해준다.</code></pre><p>( max 값이 여러개여도 상관없다. 중요한건 max의 위치가 아니라, max 값을 기준삼아서 전진하고, 전진하면서 max값과 해당 기둥의 차이를 계산하는 것 )</p>
<h1 id="📌-코드">📌 코드</h1>
<pre><code class="language-python">def trap(heights):
    if not heights:
        return 0

    volume = 0
    left=0
    right = len(heights)-1

    left_max = heights[left]
    right_max = heights[right]

    while left&lt;right:
        left_max = max(heights[left,left_max])
        right_max = max(heights[right,right_max])

        if left_max&lt;=right_max:
            volume += left_max - heights[left]
            left+=1
        else:
            volume += right_max-heights[right]
            right+=1
    return volume</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[Go 언어 시작기 #4]]></title>
            <link>https://velog.io/@camel-man-ims/Go-%EC%96%B8%EC%96%B4-%EC%8B%9C%EC%9E%91%EA%B8%B0-4</link>
            <guid>https://velog.io/@camel-man-ims/Go-%EC%96%B8%EC%96%B4-%EC%8B%9C%EC%9E%91%EA%B8%B0-4</guid>
            <pubDate>Mon, 21 Jun 2021 02:00:07 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-go-routine">📌 Go routine</h1>
<blockquote>
<p>비동기 프로그래밍을 아주 간단하게 구현할 수 있게 제공하는 기능</p>
</blockquote>
<ul>
<li><p>단, go routine은 main 함수가 끝나지 않을 때에만 의미가 있다.</p>
</li>
<li><p>Main 함수는 go routine을 기다려주지 않는다.</p>
</li>
</ul>
<pre><code class="language-go">package main

import (
    &quot;fmt&quot;
    &quot;time&quot;
)

func main() {
    go printMember(&quot;ersu&quot;)
    printMember(&quot;heechan&quot;)
}

func printMember(name string){
    for i:=0; i&lt;4; i++{
        fmt.Println(name,i)
        time.Sleep(time.Second)
    }
}</code></pre>
<p>위 코드는 아래와 같이 동작한다.</p>
<p><img src="https://images.velog.io/images/camel-man-ims/post/a94853af-7ff1-4fa6-8366-a33d06d8a2f4/1.gif" alt=""></p>
<pre><code class="language-go">go printMember(&quot;ersu&quot;)</code></pre>
<p>parameter를 ersu로 넘기는 함수에 go를 붙이면 아래와 같이 비동기적으로 작동한다.</p>
<p><img src="https://images.velog.io/images/camel-man-ims/post/418574c2-5573-4e02-a5fd-c08515326229/2.gif" alt=""></p>
<pre><code class="language-go">func main() {
    go printMember(&quot;ersu&quot;)
    go printMember(&quot;heechan&quot;)
}</code></pre>
<p>그러나 위와 같이 두 함수 모두에 go를 붙여버리면 아무것도 출력하지 않고 그냥 함수가 끝나버리는데, 이것은 main함수는 go routine을 기다려주지 않기 때문이다.</p>
<pre><code class="language-go">func main() {
    go printMember(&quot;ersu&quot;)
    go printMember(&quot;heechan&quot;)
    time.Sleep(time.Second*2)
}</code></pre>
<p>만약 main 함수에 2초라는 시간을 준다면, 2초만큼만 출력하게 된다.</p>
<p><img src="https://images.velog.io/images/camel-man-ims/post/925b6517-a452-4090-a2bc-3c9db6a8e8c5/image.png" alt=""></p>
<h1 id="📌-channel">📌 Channel</h1>
<blockquote>
<p>GO ROUTINE과 Main Function 사이에 정보를 전달하기 위한 방법
GO ROUTINE에서 다른 GO ROUTINE으로 가는 것도 가능하다</p>
<p>즉, GO ROUTINE 사이에 어떻게 커뮤니케이션을 하는 가에 대한 이야기</p>
</blockquote>
<pre><code class="language-go">package main

import &quot;time&quot;

func main() {
    people := [2]string{&quot;얼쑤&quot;,&quot;희찬&quot;}

    for _, person := range people{
        go isSexy(person)
    }
}

func isSexy(person string) bool{
    time.Sleep(time.Second*3)
    return true
}</code></pre>
<p>Golang은 go routine의 return 값을 직접적으로 받을 수 없다.</p>
<p>예를 들어 아래와 같이 값을 받을 수 없다는 말이다.</p>
<pre><code class="language-go">returnValue = go isSexy()</code></pre>
<p>그렇다면 go routine의 값은 어떻게 받아야 하는가?
이 때, Channel이 등장한다.</p>
<hr>
<h3 id="🔥-channel-생성">🔥 Channel 생성</h3>
<pre><code class="language-go">func main() {
    channel := make(chan bool)
...</code></pre>
<p>뒤에 bool인 것은, channel이 받을 return type이 boolean값인 것을 알려주는 것이다.</p>
<pre><code class="language-go">func isSexy(person string, channel chan bool) {
    fmt.Println(person)
    time.Sleep(time.Second*3)
    channel &lt;- true
}</code></pre>
<p>function의 return value를 받기 위해, parameter로 chan type을 받는다.</p>
<p>return value는 사라지고, 해당 channel에 true값을 반환한다고 명시해준다.</p>
<h2 id="🔥-channel-version1">🔥 Channel version1)</h2>
<pre><code class="language-go">func main() {
    channel := make(chan bool)
    people := [2]string{&quot;얼쑤&quot;,&quot;희찬&quot;}

    for _, person := range people{
        go isSexy(person, channel)
    }
    result := &lt;-channel
    fmt.Println(result)
}

func isSexy(person string, channel chan bool) {
    fmt.Println(person)
    time.Sleep(time.Second*3)
    channel&lt;-true
}</code></pre>
<p><img src="https://images.velog.io/images/camel-man-ims/post/5ae85d60-85ad-497c-a2d3-9670df095c54/image.png" alt=""></p>
<p>재밌는 점은, true가 한번만 출력됐다는 것이다. 이것은 채널로부터 뭔가를 받을 때, 메인 함수는 어떤 답이 올 때까지 기다린다.</p>
<pre><code class="language-go">result := &lt;-channel</code></pre>
<p>golang은 위의 메세지를 보고, 멈춰서서 메세지를 하나 받을 때까지 멈춰선다.
위 코드는 아래 코드와 동치다.</p>
<pre><code class="language-go">fmt.Println(&lt;-channel)</code></pre>
<hr>
<p>channel 을 2개 보내면 2개가 true가 찍힌다.</p>
<p>그렇다면, 3개를 찍어보면 어떻게 될까?</p>
<pre><code class="language-go">func main() {
    channel := make(chan bool)
    people := [2]string{&quot;얼쑤&quot;,&quot;희찬&quot;}

    for _, person := range people{
        go isSexy(person, channel)
    }
    fmt.Println(&lt;-channel)
    fmt.Println(&lt;-channel)
    fmt.Println(&lt;-channel)
}</code></pre>
<p><img src="https://images.velog.io/images/camel-man-ims/post/b89c0d35-b422-4512-90ed-30beaff89d99/image.png" alt=""></p>
<p>deadlock에 걸린다. 만약 배열의 크기를 3개로 정하면 다시 정상적으로 true가 3개 출력되는 것을 볼 수 있다.</p>
<p>go routine은 해당 range에 따라 go routine 수를 할당해놓는다. 그래서 할당된 go routine보다 많은 go routine이 할당되면 deadlock에 걸린다.</p>
<h2 id="🔥-channel-version-2">🔥 Channel version 2)</h2>
<p>Channel은 blocking operation 이다.</p>
<p>즉, result 값을 받을 때까지 기다린다.</p>
<pre><code class="language-go">func main() {
    channel := make(chan string)
    people := [6]string{&quot;얼쑤&quot;,&quot;희찬&quot;,&quot;규헌&quot;,&quot;종원&quot;,&quot;아이돌&quot;,&quot;강아지&quot;}

    for _, person := range people{
        go isSexy(person, channel)
    }

    result1 := &lt;- channel
    result2 := &lt;- channel
    result3 := &lt;- channel

    fmt.Println(result1)
    fmt.Println(result2)
    fmt.Println(result3)

}

func isSexy(person string, channel chan string) {
    time.Sleep(time.Second*3)
    channel&lt;- person + &quot; is sexy&quot;
}</code></pre>
<p><img src="https://images.velog.io/images/camel-man-ims/post/e34301e9-5ea1-4185-8a6e-079602d0fb20/image.png" alt=""></p>
<p><img src="https://images.velog.io/images/camel-man-ims/post/7c208098-c0f7-40d7-ba75-863227452ba7/image.png" alt=""></p>
<p><img src="https://images.velog.io/images/camel-man-ims/post/275e9f0d-4616-4087-baf8-b674eb5a7cba/image.png" alt=""></p>
<p>channel로부터 값을 받은 순서대로 값을 출력할 수 있다. 실행은 병렬적으로 되므로, 어떤 값을 먼저 받을 지는 알 수 없다.</p>
<pre><code class="language-go">func main() {
    channel := make(chan string)
    people := [6]string{&quot;얼쑤&quot;,&quot;희찬&quot;,&quot;규헌&quot;,&quot;종원&quot;,&quot;아이돌&quot;,&quot;강아지&quot;}

    for _, person := range people{
        go isSexy(person, channel)
    }
    for i:=0 ; i&lt;len(people); i++{
        fmt.Println(&lt;-channel)
    }
}

func isSexy(person string, channel chan string) {
    time.Sleep(time.Second*3)
    channel&lt;- person + &quot; is sexy&quot;
}</code></pre>
<p>매번 <code>&lt;-</code> opertion을 쓰지 않고, loop를 돌리면 n회 작업을 처리할 수 있다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 #10 (큐) - 카드2]]></title>
            <link>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-10-%ED%81%90-%EC%B9%B4%EB%93%9C2</link>
            <guid>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-10-%ED%81%90-%EC%B9%B4%EB%93%9C2</guid>
            <pubDate>Sun, 20 Jun 2021 09:04:46 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-문제">📌 문제</h1>
<p>첫번째 요소를 pop하고, 그 요소를 마지막에 집어넣는다. 마지막에 남는 요소는?</p>
<h1 id="📌-아이디어--유의점">📌 아이디어 &amp; 유의점</h1>
<p>처음에는</p>
<pre><code class="language-python">arr=[]
arr.pop[0]</code></pre>
<p>식으로 첫 요소를 뺐는데, pop[0]연산은 제거 후 재배치 때문에 O(n)이 걸린다.</p>
<p>이후 deque 자료형을 썼다.</p>
<h1 id="📌-코드">📌 코드</h1>
<pre><code class="language-python">n = int(input())
from collections import deque

q = deque()

for i in range(1,n+1):
    q.append(i)

while len(q)!=1:
    q.popleft()
    first = q.popleft()
    q.append(first)

print(q[0])</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 #9 (스택) - 괄호]]></title>
            <link>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-9-%EC%8A%A4%ED%83%9D-%EA%B4%84%ED%98%B8</link>
            <guid>https://velog.io/@camel-man-ims/%EB%B0%B1%EC%A4%80-9-%EC%8A%A4%ED%83%9D-%EA%B4%84%ED%98%B8</guid>
            <pubDate>Fri, 18 Jun 2021 05:19:16 GMT</pubDate>
            <description><![CDATA[<h1 id="📌-문제">📌 문제</h1>
<p>짝 짓는 괄호쌍이 되면 YES
아니면 NO를 출력하라</p>
<pre><code>(((())()) NO
((())) YES</code></pre><h1 id="📌-아이디어">📌 아이디어</h1>
<p>스택사용</p>
<p>주의할 점은 stack안에 값이 남아 있어도 ( = <code>(</code>가 남아있어도 ) NO라는 점</p>
<h1 id="📌-코드">📌 코드</h1>
<pre><code class="language-python"># 21.06.18

n = int(input())

for _ in range(n):
    stack = []
    s_value = input()
    flag = True

    for s in s_value:
        if s==&#39;(&#39;:
            stack.append(s)
        elif s==&#39;)&#39;:
            if stack:
                stack.pop()
            else:
                flag=False

    if flag and not stack:
        print(&quot;YES&quot;)
    else:
        print(&quot;NO&quot;)



</code></pre>
]]></description>
        </item>
    </channel>
</rss>