Skip to content

[PR][austin] 2주차 풀이 업데이트#7

Open
AndrewSRP wants to merge 1 commit intomainfrom
austin_02
Open

[PR][austin] 2주차 풀이 업데이트#7
AndrewSRP wants to merge 1 commit intomainfrom
austin_02

Conversation

@AndrewSRP
Copy link
Copy Markdown
Collaborator

Summary

// 수도코드

고민 포인트

  • heap 구현이 귀찮아서 처음에는, Object 를 이용함,
  • 잘 풀렸지만, 6번에서 계속 타임아웃이 걸림
  • Object.keys 가 생각보다 리소스를 많이 잡아먹음
  • heap 정렬로 구현시 비교도 안되게 빠름 ㅠ
class Helper {
    counter = {}
    min = -1
    push (enemyCount) {
        const min = this.min
        if (min === -1 || enemyCount < min) {
            this.min = enemyCount
        }
        const count = this.counter[enemyCount]
        if (count) {
            this.counter[enemyCount]++
        } else {
            this.counter[enemyCount] = 1
            this.size ++
        }
    }
    pop () {
        const min = this.min
        if (this.counter[min] - 1) {
            this.counter[min]--
        } else {
            delete this.counter[min]
            this.size--
            if (this.size === 0) {
                this.min = -1
            } else {
                this.min = Object.keys(this.counter)[0]   
            }
        }
        return min
    }
}

리뷰어 Check-list

  • 가독성이 괜찮나요?
  • 엣지케이스를 대응하였나요?

@AndrewSRP AndrewSRP self-assigned this Jul 24, 2023
@AndrewSRP AndrewSRP linked an issue Jul 24, 2023 that may be closed by this pull request
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.

2주차 문제

1 participant