문제링크: 실패율
✍🏻 Information
| content | |
|---|---|
| 언어 | python |
| 난이도 | ⭐️⭐️ |
| 풀이시간 | 25분 |
| 제출횟수 | 3 |
| 인터넷검색유무 | yes |
🍒 My Code
def solution(N, stages):
answer = []
possibility = [] #각 stage의 실패율
#stages.sort() -> sorting 안해줘도 됨
num = [0] * (N+1) #각 stage에 있는 사람수
for i in stages:
num[i-1]+=1
SUM=0
for i in range(len(num)-1,-1,-1):
SUM += num[i]
if i==(len(num)-1):
continue
if SUM==0:
possibility.insert(0,0)
else:
possibility.insert(0,num[i]/SUM)
for i in range(len(possibility)):
idx = possibility.index(max(possibility))
answer.append(idx+1)
possibility[idx]=-1
return answer
💡 What I learned
[0 for i in range (N+1)] 해주면 오류가 떴다. 다시하면 안뜬다...?count 메소드를 쓸 수도 있다!max로 처리 안하고 sort로 처리할 수 있다list_name.index(max(list_name))
list_name.index(min(list_name))
list에 값을 추가하는 메소드
1) append(value): 맨 뒤에 value 삽입 -> 만약 value가 list일 경우 한 index에 list 전체가 삽입된다
2) extend(value): 맨 뒤에 value 삽입 -> 만약 value가 list일 경우 배열 안의 각 아이템이 추가된다
3) insert(idx,value): idx 위치에 value를 삽입
#예제1
a = ['a','b','c','d']
b = ['e','f']
a.append(b)
a
>> ['a', 'b', 'c', 'd', ['e', 'f']]
#예제2
a = ['a','b','c','d']
b = ['e','f']
a.extend(b)
a
>> ['a', 'b', 'c', 'd', 'e', 'f']