반응형
카드 뭉치(프로그래머스 Lv.1)
https://school.programmers.co.kr/learn/courses/30/lessons/159994
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
내 코드
def solution(cards1, cards2, goal):
answer = "Yes"
locate_1, locate_2 = 0, 0
for go in goal:
if locate_1 < len(cards1) and go == cards1[locate_1]:
locate_1 += 1
elif locate_2 < len(cards2) and go == cards2[locate_2]:
locate_2 += 1
else:
answer = "No"
return answer
return answer
파이썬은 선빵필승의 코드, list 범위를 넘지 않도록 아래처럼 범위를 잡아주어야 했다.
if locate_1 < len(cards1) and go == cards1[locate_1]:
반응형
'Python공부 > 프로그래머스' 카테고리의 다른 글
(Python) 공원 산책 (프로그래머스 Lv.1) (0) | 2023.06.19 |
---|---|
(Python) 실패율 (프로그래머스 Lv.1) (0) | 2023.06.19 |
(Python) 모의고사 (프로그래머스 Lv1) (0) | 2023.06.16 |
(Python) 과일 장수 (프로그래머스 Lv.1) (0) | 2023.06.16 |
(Python) 명예의 전당(1) (프로그래머스 Lv.1) (0) | 2023.06.16 |