문제: https://school.programmers.co.kr/learn/courses/30/lessons/92334
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
방법1: 테스트3 시간초과
def solution(id_list, report, k):
warned_id, user_id, mail_id = [], [], []
#중복 삭제
report = list(set(report))
#신고자, 신고받은자 구분
for ID in (report):
tmp = ID.split(' ')[1]
warned_id.append(tmp)
tmp = ID.split(' ')[0]
user_id.append(tmp)
answer = dict.fromkeys(id_list,0)
# k번이상 걸리면
for name in id_list:
if warned_id.count(name) >= k:
#이메일 발송이 필요한 id 도출
for index,reported_id in enumerate(warned_id):
if reported_id == name:
answer[str(user_id[index])] += 1
return list(answer.values())
방법2 : 테스트3,11,21 시간초과
def solution(id_list, report, k):
answer = []
warned_id, user_id, mail_id = [], [], []
#중복 삭제
report = list(set(report))
#신고자, 신고받은자 구분
for ID in (report):
tmp = ID.split(' ')[1]
warned_id.append(tmp)
tmp = ID.split(' ')[0]
user_id.append(tmp)
# k번이상 걸리면
for name in id_list:
if warned_id.count(name) >= k:
#이메일 발송이 필요한 id 도출
for index,reported_id in enumerate(warned_id):
if reported_id == name:
mail_id.append(user_id[index])
for name in id_list:
answer.append(mail_id.count(name))
return answer
방법3 : 테스트3,9,10,11,14,15 시간초과
import pandas as pd
def solution(id_list, report, k):
answer = []
#현재 id리스트 설정
# 행 :신고 한사람 , 열 : 신고당항사람
df_id = pd.DataFrame(columns=id_list,index=id_list).fillna(0)
# 리포트 정리
for i in report:
tmp = i.split()
if df_id.loc[tmp[1], tmp[0]] == 0:
df_id.loc[tmp[1], tmp[0]] += 1
# del tmp
warning_result = list(df_id.sum(axis=1))
# print("신고당한 횟수", (warning_result))
# k값대비 확인
for i in range(0,len(warning_result)):
if warning_result[i] < k:
df_id.iloc[i] = 0
# report_result = list(df_id.sum(axis=0))
# print('처리결과 메일', (report_result))
return list(df_id.sum(axis=0))
반응형
'공부 서랍장 > 알고리즘 공부' 카테고리의 다른 글
[프로그래머스] H-Index python (0) | 2022.09.18 |
---|---|
[프로그래머스] 성격 유형 검사하기 python (0) | 2022.09.18 |
[프로그래머스] 이상한 문자 만들기 python (0) | 2022.09.17 |
[프로그래머스] 최소직사각형 python (0) | 2022.09.17 |
[프로그래머스] [1차]비밀지도 python (0) | 2022.09.17 |