Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions contains-duplicate/jjipper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* https://leetcode.com/problems/contains-duplicate
* time complexity : O(n)
* space complexity : O(n)
*/

export function containsDuplicate(nums: number[]): boolean {
const seen = new Set<number>();
for (const num of nums) {
if (seen.has(num)) {
return true;
}
seen.add(num);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

이 방식이라면 Set에 모든 숫자를 넣지 않는 경우도 생겨서
모두 넣고 사이즈를 비교하는 방식보다 효율적일 것 같습니다.
의미도 명확해서 좋은 풀이인 것 같네요!

}
return false;
};
18 changes: 18 additions & 0 deletions two-sum/jjipper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* https://leetcode.com/problems/two-sum
* time complexity : O(n)
* space complexity : O(n)
*/

export function twoSum(nums: number[], target: number): number[] {
const obj: Record<number, number> = {};
for (let i = 0; i < nums.length; i++) {
const a = nums[i];
const b = target - a;
if (b in obj) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

깔끔한 풀이네요.
변수명을 보다 의미있게 작성하면 가독성에 도움이 될 것 같습니다!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

앗 그러네요 변수명도 의미있게 작성하도록 신경써야겠습니다.
좋은 피드백 감사드립니다 도현님! 😀

return [obj[b], i];
}
obj[a] = i;
}
return [];
};