
https://school.programmers.co.kr/learn/courses/30/lessons/159994
def solution(c1, c2, goal):
for i in goal:
if c1[0] == i:
c1.pop(0)
c1.append(0)
elif c2[0] == i:
c2.pop(0)
c2.append(0)
else:
return "No"
return "Yes"
나는 index error가 나지 않도록 pop을 해준 다음 다시 append를 해 주었는데
def solution(cards1, cards2, goal):
for g in goal:
if len(cards1) > 0 and g == cards1[0]:
cards1.pop(0)
elif len(cards2) >0 and g == cards2[0]:
cards2.pop(0)
else:
return "No"
return "Yes"
이런 식으로 먼저 길이를 체크한다면 굳이 append를 하지 않아도 될 것이다
| [파이썬/python] 백준 10844번 : 쉬운 계단 수 (🥈1) (0) | 2023.07.05 |
|---|---|
| [파이썬/python] 백준 11053번 : 가장 긴 증가하는 부분 수열 (🥈2) (0) | 2023.07.05 |
| [파이썬/python] 프로그래머스 : 모의고사 (Lv.1) (0) | 2023.07.05 |
| [파이썬/python] 프로그래머스 : 추억 점수 (Lv.1) (0) | 2023.07.05 |
| [파이썬/python] 백준 1932번 : 정수 삼각형(🥈1) (0) | 2023.07.02 |