Skip to content

Conversation

@jungmyunggi
Copy link
Collaborator

문제

Type Info
Time Complexity O(n)
Space Complexity O(1)
Algorithm 슬라이딩 윈도우
Data Structure x

Constraints

  • n == nums.length
  • 1<= k <= n <= 10^5
  • -10^4 <= nums[i] <= 10^4

Edge Case

  • 없음

풀이

max = -무한대
teml = 0

for(i는 0부터 k-1까지){
  temp += nums[i]
}
max = temp

for(i는 k부터 nums마지막 까지){
  temp = temp - nums[i-k] + nums[i]
  max = Math.max(temp, max)
}

return max/k

어려웠던 점

  • 배열 인덱스관리

알게된 점

  • 슬라이딩 윈도우

Copy link
Member

@BangDori BangDori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오.. 생각치도 못한 방법이네요.

n번의 반복문 내부에서만 처리해야 한다는 생각에 잠겨서, 미리 k번을 더해주고 슬라이딩 윈도우 방식으로 이동한다는 걸 생각하지 못했는데 배우고 갑니다~

@jungmyunggi jungmyunggi merged commit 60f0f5d into main Jan 2, 2025
2 checks passed
@BangDori BangDori deleted the jungmyunggi/maximum-average-subarray-i branch January 10, 2025 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants