프로그래머스 코딩테스트/Python
프로그래머스 카드 뭉치 Python
Coding-Su
2024. 6. 26. 00:06
728x90
정답
def solution(cards1, cards2, goal):
answer = 'No'
while len(goal) > 0:
if len(cards1) != 0 and goal[0] == cards1[0]:
cards1.pop(0)
goal.pop(0)
elif len(cards2) != 0 and goal[0] == cards2[0]:
cards2.pop(0)
goal.pop(0)
else:
break
if len(goal) == 0:
answer = 'Yes'
return answer
한번 사용한 카드는 다시 사용할 수 없음으로 list에서 pop을 통하여 제거했습니다. 또한 앞에있는 카드만 사용할 수 있음으로 앞에서부터 비교 후 같으면 pop 다르면 break를 이용하여 풀었습니다.
728x90