일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- Python
- data science
- 715. Range Module
- concurrency
- 43. Multiply Strings
- Python Code
- 컴퓨터의 구조
- 프로그래머스
- Decorator
- 30. Substring with Concatenation of All Words
- iterator
- Generator
- 운영체제
- 315. Count of Smaller Numbers After Self
- Regular Expression
- t1
- 파이썬
- 시바견
- shiba
- 밴픽
- 109. Convert Sorted List to Binary Search Tree
- attribute
- Class
- kaggle
- Substring with Concatenation of All Words
- Protocol
- Python Implementation
- Convert Sorted List to Binary Search Tree
- LeetCode
- DWG
Archives
- Today
- Total
Scribbling
프로그래머스: 모의고사 본문
Generator를 이용한 해법
def solution(answers):
def gen1():
candidates = [1, 2, 3, 4, 5]
while True:
for candidate in candidates:
yield candidate
def gen2():
candidates = [2, 1, 2, 3, 2, 4, 2, 5]
while True:
for candidate in candidates:
yield candidate
def gen3():
candidates = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
while True:
for candidate in candidates:
yield candidate
g1 = gen1()
g2 = gen2()
g3 = gen3()
answer = []
correct = [0] * 3
for answer in answers:
if next(g1) == answer:
correct[0] += 1
if next(g2) == answer:
correct[1] += 1
if next(g3) == answer:
correct[2] += 1
answer = [i+1 for i in range(3) if correct[i] == max(correct)]
return answer
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 103. Binary Tree Zigzag Level Order Traversal (0) | 2021.10.20 |
---|---|
LeetCode: 102. Binary Tree Level Order Traversal (0) | 2021.10.20 |
프로그래머스: 카펫 (0) | 2021.10.19 |
프로그래머스: 소수 찾기 (0) | 2021.10.19 |
프로그래머스: H-Index (0) | 2021.10.18 |