[프로그래머스] 순위 검색
2021 KAKAO BLIND RECRUITMENT 문제입니다.
처음 풀었던 풀이
def solution(info, query):
info_list = []
answer = []
for i in info:
one_info = list(i.split())
info_list.append(one_info)
for j in query:
q = list(j.split(' and '))
q[3], a = q[3].split()
q.append(a)
# 해당조건에 맞는 사람을 one_info에서 찾아서 count하기
count = 0
for k in info_list:
if (k[0]==q[0] or q[0]=='-') and (k[1]==q[1] or q[1]=='-') and (k[2]==q[2] or q[2]=='-') and (k[3]==q[3] or q[3]=='-') and int(k[4])>=int(q[4]):
count += 1
answer.append(count)
return answer
두번째 풀이
def solution(info, query):
info_list = []
query_list = []
answer = []
for i in info:
one_info = list(i.split())
info_list.append([one_info[:4], int(one_info[4])])
for j in query:
q = list(j.split(' and '))
q[3], query_score = q[3].split()
query_list.append([[x for x in q if x !='-'], int(query_score)])
for query_person in query_list:
count = 0
for info_person in info_list:
info_con = set(info_person[0])
query_con = set(query_person[0])
if query_person[1] <= info_person[1]:
if info_con.intersection(query_con)==query_con:
count += 1
answer.append(count)
return answer
느낀 점
두 풀이 다 효율성테스트를 통과하지 못했다..ㅠㅠ dictionary나 hash로 접근해보기!!
댓글남기기