이 패턴은 반복 루프의 각 후속 반복 사이에 겹치는 윈도우나 범위를 재사용할 수 있도록 해
줍니다. 첫 번째 반복에서는 첫 반복에 필요한 범위 내의 모든 것을 합산합니다. 루프의 두
번째 반복에서는 두 번째 반복 범위를 처음부터 다시 합산하는 대신, 첫 번째 반복의 총합에
새 숫자를 더하고 첫 번째 숫자를 빼는 방법을 사용합니다. 이렇게 함으로써 일정 범위 안에
있는 모든 값을 합산하는 작업이 훨씬 단순한, 숫자 세개만을 다루는 문제로 변모합니다. 이
방법을 적용해보니, 이전에 실패했던 많은 문제들이 이제는 큰 범위의 숫자를 다룰 때에도
테스트 케이스를 통과했습니다.
이제 몇 가지 문제 예제들을 살펴보며 이해를 돕겠습니다. 릿코드와 같은 많은 온라인 플랫
폼들은 여러분이 코드를 삽입할 수 있는 사전에 정의된 클래스와 같은 보일러플레이트 코드
를 제공합니다. 그러나 이 책에서는 간결한 설명을 위해 예시 문제와 답변에서는 보일러플레
이트를 포함하지 않겠습니다.
문제
5
-
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.