일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- attribute
- 컴퓨터의 구조
- 30. Substring with Concatenation of All Words
- Python Code
- LeetCode
- Generator
- 43. Multiply Strings
- 프로그래머스
- Decorator
- 운영체제
- iterator
- t1
- 715. Range Module
- Regular Expression
- 109. Convert Sorted List to Binary Search Tree
- Convert Sorted List to Binary Search Tree
- 시바견
- Substring with Concatenation of All Words
- Class
- kaggle
- concurrency
- DWG
- data science
- 파이썬
- 밴픽
- 315. Count of Smaller Numbers After Self
- Protocol
- Python
- shiba
- Python Implementation
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 |