-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1주차] 재귀, 꼬리 재귀, 꼬리 재귀 최적화 #14
Open
whoodongpyo
wants to merge
8
commits into
CodeSoom:main
Choose a base branch
from
whoodongpyo:week1-phd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c08b970
feat: 총합 구하기 풀이
whoodongpyo c0432e3
feat: 피보나치 수 풀이
whoodongpyo 220575c
feat: 2진수로 변환하기
whoodongpyo aafb860
feat: 이진수 10진수로 변환하기 풀이
whoodongpyo 0c711ba
feat: 유클리드 호제법으로 최대 공약수 구하기 풀이
whoodongpyo 2b28f2b
feat: 계단 오르기 풀이
whoodongpyo 8c7daa8
refactor: 총합 구하기
whoodongpyo 4753e25
refactor: 피보나치 수
whoodongpyo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
주어진 배열의 마지막을 하나씩 제거하면서 값을 더해주고 있군요. 여기서 pop메서드는 배열의 가장 끝에 있는 요소를 제거하는 것으로 배열 자체를 변경하게 됩니다. 그리고 제일 뒤에 있는 것을 제거하기 때문에 만약 지금처럼 값을 더하는 것이 아니라 이어 붙이는 작업이었다면 순서가 달라질 수 있겠죠.
pop으로 배열 자체를 수정한다면 numbers를 참조하는 곳에서도 변경이 일어납니다. 그러면 의도치 않은 변경때문에 심각한 버그가 발생할 수 있습니다. 그래서 만약 하나를 제거하고 나머지 배열을 넘기고 싶다면
slice
메서드를 사용할 수 있습니다. slice메서드는 원본 배열을 건드리지 않고 복사합니다.혹은 이렇게도 할 수 있습니다.
그런데 이렇게 값들을 복사하는 것은 효율적이지는 않습니다. 그래서 성능을 최적화하기 위해서는 배열을 복사하는 대신 index를 사용할 수 있습니다. index의 값을 변경하는 것은 데이터의 크기이 비례하지 않기 때문입니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
가장 익숙한 방법인 for loop 으로 해결할 땐 당연하게(?) index 를 사용했는데
정작 꼬리 재귀 최적화에서는 index 를 떠올리지 못한 게 아쉽네요 😭
코멘트 해주신대로, 데이터 원본을 직접적으로 수정하지 않도록 습관화해야겠습니다!