Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions missing-number/HerrineKim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 시간 복잡도: O(n)
// 공간 복잡도: O(n)

/**
* @param {number[]} nums
* @return {number}
*/
var missingNumber = function(nums) {
const numSet = new Set(nums);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set 자료구조로 데이터 조회 시간복잡도를 O(1)로 처리하신 부분이 좋아보여요 👍
메모리를 좀 더 활용하게 되어서 공간복잡도가 O(N) 이 되었는데, O(1) 로 더 최적화 할 수 있는 방법은 없을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GangBean 가우스 덧셈 공식을 사용해 최적화해봤습니다! 🙇


for (let i = 0; i <= nums.length; i++) {
if (!numSet.has(i)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 언어에 대한 제 조그만 궁금증인데.. 변수 타입 예약어가 var, const, let 3가지가 보여서요. 어떤 차이가 있는 건지 궁금하네요 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 언어에 대한 제 조그만 궁금증인데.. 변수 타입 예약어가 var, const, let 3가지가 보여서요. 어떤 차이가 있는 건지 궁금하네요 🤔

@GangBean 몇 가지 차이들이 있는데, 가장 중요한 차이점은 var는 업데이트, 재선언 모두 가능, let은 업데이트만 가능, const는 둘 다 불가능하다 이게 가장 큰 특징인 것 같습니다 😄 (요 글 참고해서 알아보았네요: https://www.freecodecamp.org/korean/news/var-let-constyi-caijeomeun/)

return i;
}
}
};

Loading