2022 KAKAO BLIND RECRUITMENT 신고 결과 받기 (lv1)


정답코드

def solution(id_list, report, k):
    answer = []
    report_dict = {id : [] for id in id_list}
    mail_count = {id : 0 for id in id_list}
    
    for r in set(report): #set은 중복 제거용
    	report_dict[r.split()[1]].append(r.split()[0]) 
        #신고 당한 사람의 딕셔너리에 누가 신고했는지 추가

    for key, value in report_dict.items():
        if len(value) >= k: #신고 당한 횟수가 k 이상이면
            for v in value:
                mail_count[v] += 1  # v는 신고자

    for i in mail_count:
        answer.append(mail_count[i])

    return answer

다른 정답코드

def solution(id_list, report, k):
   answer = [0] * len(id_list)    
   reports = {x : 0 for x in id_list}

   for r in set(report):
       reports[r.split()[1]] += 1

   for r in set(report):
       if reports[r.split()[1]] >= k:
           answer[id_list.index(r.split()[0])] += 1

   return answer
  

#--------------------------------------------------------

def solution(id_list, report, k):
   answer = []
   a = list(set(report))
   dictionary2 = {name : 0 for name in id_list}
   dictionary = {name : [] for name in id_list}
   for i in a:
       dictionary[i.split()[1]].append(i.split()[0])

   for i in dictionary:
       if len(dictionary[i]) >= k:
           for j in dictionary[i]:
               dictionary2[j] += 1

   for i in dictionary2:
       answer.append(dictionary2[i])

   return answer

좋은 웹페이지 즐겨찾기