-
-
Notifications
You must be signed in to change notification settings - Fork 195
[Sophia] Week3 Solutions #394
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
Conversation
ways[1] = 1; | ||
|
||
for (let i = 2; i <= n; i++) { | ||
ways[i] = ways[i - 1] + ways[i - 2]; // 점화식 사용 |
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.
점화식을 이용하신 부분이 좋습니다! 👍 조금 더 개선해서 공간 복잡도를 O(1)
으로 줄여보시면 어떨까요?
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.
수고하셨습니다!
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.
@seona926 님 풀이 잘 보았습니다! 한 주 고생많으셨습니다~
let twoSum = function (nums, target) { | ||
let indices = {}; | ||
|
||
nums.forEach((item, 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.
16 line
의 조건을 만족하지 않는 경우, 즉, 필요한 경우에만 indices를 추가해준다면 순회 1회를 줄일 수 있지 않을까요?
for (let i = 0; i < nums.length; i++) { | ||
let findNum = target - nums[i]; | ||
|
||
if (indices[findNum] !== i && findNum.toString() in indices) { |
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.
findNum.toString()
은 아마 object의 key로 number를 사용하는 부분을 신경 써 주신것 같은데 맞을까요?
이런 목적이 맞으시다면, Map을 사용하는것도 좋지 않을까 싶습니다! 의도적으로 object를 사용하셨다면 무시하셔도 좋습니다!
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.