Skip to content

kyj 프로그래머스 디펜스 게임#173

Open
yongjun-0903 wants to merge 1 commit into
algorithm1313:mainfrom
yongjun-0903:05-12
Open

kyj 프로그래머스 디펜스 게임#173
yongjun-0903 wants to merge 1 commit into
algorithm1313:mainfrom
yongjun-0903:05-12

Conversation

@yongjun-0903
Copy link
Copy Markdown
Collaborator

📝 문제 정보

  • 문제 이름: 디펜스 게임
  • 출처: 프로그래머스

🚀 해결 방법

  • heapq를 사용하여 자동 정렬을 통해 무적권을 사용할 수 있는 라운드인지 판단할려고 하였음

📌 핵심 아이디어

  • heapq

⏳ 시간 복잡도

  • O(n log k)

✅ 실행 결과

image

💡 기타 참고 사항

from collections import deque
def solution(n, k, enemy):
    q = deque(enemy)
    answer = 0
    remaining = list(enemy)
    while q:
        ene = q.popleft()
        remaining.pop(0)
        if n < ene:  
            if k > 0:  
                k -= 1
                answer += 1
            else: 
                return answer
        else: 
            if remaining and ene >= max(remaining) and k > 0:  
                k -= 1  
            else: 
                n -= ene
            answer += 1
    return answer 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant