카드 뭉치
첫번째 코드
두 개의 리스트에서 하나씩 인덱스를 미뤄가면서 가능하면 답에 넣고 아니면 넣지 않는 방법으로 진행한다.
그러므로 투포인터를 사용해서 풀면 되겠구나!! 라고 생각했다.
def solution(cards1, cards2, goal):
answer = ""
index1 = 0
index2 = 0
A = []
for i in goal:
if i == cards1[index1]:
A.append(cards1[index1])
if index1 < (len(cards1) - 1):
index1 += 1
elif i == cards2[index2]:
A.append(cards2[index2])
if index2 < (len(cards2) - 1):
index2 += 1
else:
break
if A == goal:
answer += "Yes"
else:
answer += "No"
return answer
통과!
나름 이제 배웠던 것도 잘 써먹고 뿌듯하다 나 자신:)
링크
programmers/프로그래머스/1/159994. 카드 뭉치 at main · ornni/programmers
repository for recording Programmers Algorithm problem solving - ornni/programmers
github.com