Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 프로그래머스 파이썬
- leetcode
- 자연어처리
- programmers
- github
- 편스토랑 우승상품
- 캐치카페
- 파이썬
- 더현대서울 맛집
- 프로그래머스
- Kaggle
- 편스토랑
- PYTHON
- ubuntu
- 맥북
- SW Expert Academy
- Baekjoon
- 데이콘
- 코로나19
- Git
- dacon
- 금융문자분석경진대회
- 백준
- gs25
- 우분투
- Real or Not? NLP with Disaster Tweets
- AI 경진대회
- hackerrank
- ChatGPT
- Docker
Archives
- Today
- Total
솜씨좋은장씨
[Programmers] 카드 뭉치 (Python) 본문
728x90
반응형

코딩 1일 1문제! 오늘의 문제는 프로그래머스의 카드 뭉치 입니다.
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
👨🏻💻 문제 풀이
1. cards1 과 cards2 에서 왼쪽부터 하나씩 꺼내올때 사용하는 idx 를 각각 만들어 줍니다.
card1_idx, card2_idx = 0, 0
2. goal list 왼쪽부터 단어를 하나씩 꺼내오고 이를 cards1과 cards2 에서 왼쪽부터 하나씩 꺼내온 값과 비교하고 같은 경우 idx 를 +1 합니다.
이때 만약 cards 리스트 길이보다 idx 값이 큰 경우 정답을 No 라고 합니다.
for word in goal:
if len(cards1) > card1_idx and word == cards1[card1_idx]:
card1_idx += 1
elif len(cards2) > card2_idx and word == cards2[card2_idx]:
card2_idx += 1
else:
answer = "No"
break
👨🏻💻 코드 ( Solution )
def solution(cards1, cards2, goal):
answer = 'Yes'
card1_idx, card2_idx = 0, 0
for word in goal:
if len(cards1) > card1_idx and word == cards1[card1_idx]:
card1_idx += 1
elif len(cards2) > card2_idx and word == cards2[card2_idx]:
card2_idx += 1
else:
answer = "No"
break
return answer
GitHub - SOMJANG/CODINGTEST_PRACTICE: 1일 1문제 since 2020.02.07
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[Programmers] 분수의 덧셈 (Python) (0) | 2023.02.21 |
---|---|
[Programmers] 옹알이 (2) (Python) (0) | 2023.02.20 |
[Programmers] 컨트롤 제트 (Python) (0) | 2023.02.18 |
[Programmers] OX퀴즈 (Python) (0) | 2023.02.16 |
[Programmers] 연속된 수의 합 (Python) (0) | 2023.02.15 |