-
Notifications
You must be signed in to change notification settings - Fork 126
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
[YeomChaeeun] Week 4 #818
[YeomChaeeun] Week 4 #818
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.
@YeomChaeeun 님, 2024년 한해 고생 많으셨습니다.
2025년에도 완주까지 꼭 참여해주시면 좋겠습니다!
아직 풀이중이시니 코멘트만 남기겠습니다. 새해 복 많이 받으세요!
|
||
nums.sort((a, b) => a - b) | ||
|
||
for(let i = 0; i < nums.length; 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.
오,, 처음엔 순회 범위가 잘못된줄 알았는데요,
혹시 마지막 숫자가 비어있는 경우를 nums[i + 1]
이 undefined
가 나오도록 해서 false
를 유도하고 nums[i] + 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.
넵 맞습니다!
[0, 1] 이 예시라면 nums[1] + 1 !== undefined 가 되어서
최종적으론 nums[1] + 1 인 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.
안녕하세요! 저랑 풀이가 비슷한 듯 달라서 흥미롭기도 하고 많이 배웠습니다👍
새해 복 많이 받으세요 :)
for (const coin of coins) { | ||
for (let i = coin; i <= amount; i++) { | ||
dp[i] = Math.min(dp[i], dp[i - coin] + 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.
저는 이중 for문에서 바깥쪽 for문을 amount로 했는데,
바깥쪽 for문을 coin으로 하면 더 간결한 코드로 같은 결과를 도출할 수 있어서 좋은 것 같습니다!
* @param list2 | ||
*/ | ||
function mergeTwoLists(list1: ListNode | null, list2: ListNode | null): ListNode | null { | ||
if(!(list1 && list2)) return list1 || list2 |
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.
타입스크립트는 논리 연산자를 활용하여 간결하게 값 선택 및 조건 처리를 할 수 있는게 좋은 것 같네요!
if(list1.val < list2.val) { | ||
list1.next = mergeTwoLists(list1.next, list2); | ||
return list1 | ||
} else { | ||
list2.next = mergeTwoLists(list2.next, list1); | ||
return list2 | ||
} |
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(let i = 0; i < nums.length; i++) { | ||
if(nums[0] !== 0) return 0 | ||
if(nums[i] + 1 !== nums[i + 1]) | ||
return nums[i] + 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.
nums[i]를 swap하는 방식 혹은 bit연산을 활용해서 O(N)의 시간복잡도로 줄여보는 것도 좋을 것 같아요
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
로 설정해주세요.