๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/159994
ํ์ด
# ํ๋ก๊ทธ๋๋จธ์ค 2๋จ๊ณ - ์นด๋ ๋ญ์น
from collections import deque
def solution(cards1, cards2, goal):
cards1 = deque(cards1)
cards2 = deque(cards2)
for i in range(len(goal)):
if cards1 and cards1[0] == goal[i]:
cards1.popleft()
elif cards2 and cards2[0] == goal[i]:
cards2.popleft()
else:
return "No"
return "Yes"
print(solution(["i", "drink", "water"],["want", "to"],["i", "want", "to", "drink", "water"]))
print(solution(["i", "water", "drink"],["want", "to"],["i", "want", "to", "drink", "water"]))
Deque๋ฅผ ์ฌ์ฉํด์ ํ ์ ์๋ ๋ฌธ์ ์ด๋ค.
'๐๏ธ Algorithm > โฌ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
โฌ [Programmers] [Python] [Level3] ์ฌํ ๊ฒฝ๋ก (1) | 2023.05.10 |
---|---|
โฌ [Programmers] [Python] [Level2] ์นด๋ ๋ญ์น (1) | 2023.05.10 |
โฌ [Programmers] [Python] [Level2] ๋ ๋งต๊ฒ (0) | 2023.04.17 |
โฌ [Programmers] [Python] [2018 KAKAO BLIND RECRUITMENT] [Level2] [3์ฐจ] n์ง์ ๊ฒ์ (0) | 2023.04.17 |
โฌ [Programmers] [Python] [2018 KAKAO BLIND RECRUITMENT] [Level2] [3์ฐจ] ์์ถ (0) | 2023.04.14 |