[프로그래머스] 순위검색

JinUk Lee·2023년 2월 10일
0

프로그래머스

목록 보기
13/47

https://school.programmers.co.kr/learn/courses/30/lessons/72412

첫번째 풀이


def solution(info, query):
    # 1< info < 50000
    # 1 < query < 100000
    answer = []
    for q in query:
        q = q.split()
        while 'and' in q:
            q.remove('and')
        while '-' in q:
            q.remove('-')
        count=0
        for i in info:
            i = i.split()
            check = True
            for elem in q:
                if elem.isdigit():
                    if int(i[-1]) < int(elem):
                        check = False
                else:
                    if elem not in i:
                        check = False

            if check:
                count+=1

        answer.append(count)


    return answer

정확성테스트는 통과했지만 효율성테스트는 하나도 통과를 하지 못했다.

info가 50000이고 query가 100000인데

이걸 전부 비교하면 50000*100000 이라 많은 횟수의 연산이 필요해서 효율성이 떨어진것같다.

profile
개발자 지망생

0개의 댓글