-
-
Notifications
You must be signed in to change notification settings - Fork 195
[RiaOh] WEEK 01 solutions #1172
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
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.
고생하셨습니다!
var containsDuplicate = function (nums) { | ||
let count = [nums[0]]; | ||
for (let i = 1; i < nums.length; i++) { | ||
if (count.includes(nums[i])) { |
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.
includes()는 내부적으로 for문처럼 동작하는 것일까요?
조금 더 개선된 성능을 원하신다면 Set자료구조를 사용해보시는 것도 방법이 될 수 있을 것 같습니다!
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.
오! 네 감사합니다. set자료구조로 풀어보겠습니다 :)
const arr = new Array(nums.length + 1); | ||
arr[0] = 0; | ||
arr[1] = nums[0]; | ||
for (let i = 2; i < arr.length; i++) { | ||
arr[i] = Math.max(arr[i - 1], arr[i - 2] + nums[i - 1]); | ||
} | ||
return arr[arr.length - 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.
dp를 활용하면 코드가 훨씬 간단해지고 깔끔해지는 것 같네요!
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.
감사합니다 :)
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!