2024 Day 2: Red-Nosed Reports #106
Open
+1,118
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
✔️ Solution
Part 1: 리스트가 인접 숫자 간 차이가 1에서 3 사이여야 하고, 연속적으로 늘거나 줄어드는지 확인한다.
Part 2: 각 Report 마다 level을 하나씩 뺀 리포트를 재생성하여, Part 1 의 검증 방식을 통과하는 것이 하나라도 있으면 유효하다고 판단한다.
주요 개선 사항:
isReportValid
와isReportValidWithTolerance
로 분리하여 가독성 향상.parseInput
함수로 추출하여 중복 제거.zipWithNext
를 활용하여 성능을 최적화.✔️ Reference