-
-
Notifications
You must be signed in to change notification settings - Fork 245
[Yg-cho] WEEK 01 Solutions #1707
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
base: main
Are you sure you want to change the base?
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.
고생하셨습니다
코멘트를 남기지 않은 문제는 저와 풀이가 너무 유사해서 놀랐습니다 ㅎㅎ
* @return {boolean} | ||
*/ | ||
var containsDuplicate = function(nums) { | ||
return new Set(nums).size !== nums.length; |
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.
전 개수를 세서 2개이상인지 판단했는데 set을 이용한건 되게 좋은 아이디어네요
let longest = 0; | ||
|
||
for (const num of numSet) { | ||
if(!numSet.has(num-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.
자바스크립트는 익숙치 않아서 제가 제대로 이해한진 잘 모르겠습니다
의도가 numSet을 순회하면서 더 작은게 없는지 체크하는 용도로 쓰신 if절이라면
순회 전에 numSet을 sort하면 if문을 사용하지 않아도 될것 같아요. 근데 시간복잡도를 생각해보면 if문이 더 유리할 수 있겠어요!
저도 처음엔 중첩루프로 풀었는데요, dynamic programming을 이용해서 nums와 동일한 크기의 배열을 만들고
배열값이 현재까지의 최대연속된 숫자의 개수로 업데이트하는 방식으로 풀면 단일루프로도 풀 수 있더라고요
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.
안녕하세요.
sort를 하기 보다, 현재 숫자보다 작은 num-1이 존재하지 않으면 현재 숫자가 이전 보다 작으니 시작점으로 보고, 해당 값부터 증가해 나가면서 연속된 횟수를 찾았습니다.
어떤 순서로 순회하든 모든 시작점을 다 찾게 되고, 순서는 결과에 영향이 없다고 생각하여 sort하진 않았습니다.
리뷰 감사합니다~
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!