링크
내 풀이(O)
def solution(cards1, cards2, goal):
answer = ''
for target in goal:
if len(cards1) > 0 and target == cards1[0]:
cards1.pop(0)
elif len(cards2) > 0 and target == cards2[0]:
cards2.pop(0)
else:
answer = 'No'
break
answer = 'Yes'
return answer
다른 풀이
검증용 코드
cards1s = [["i", "drink", "water"], ["i", "water", "drink"]]
cards2s = [["want", "to"], ["want", "to"]]
goals = [["i", "want", "to", "drink", "water"], ["i", "want", "to", "drink", "water"]]
results = ["Yes", "No"]
for idx in range(len(results)):
print(idx, '성공' if solution(cards1s[idx], cards2s[idx], goals[idx]) == results[idx] else "실패")