Skip to content
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

[Wan] Week 3 #765

Merged
merged 5 commits into from
Dec 28, 2024
Merged
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions two-sum/taewanseoul.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* 1. Two Sum
* Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
* You may assume that each input would have exactly one solution, and you may not use the same element twice.
* You can return the answer in any order.
*
* https://leetcode.com/problems/two-sum/description/
*/
function twoSum(nums: number[], target: number): number[] {
const map = new Map<number, number>();

for (let i = 0; i < nums.length; i++) {
if (map.has(target - nums[i])) {
return [i, map.get(target - nums[i])!];
}
map.set(nums[i], i);
}
}

// O(n) time
// O(n) space
Copy link
Contributor

Choose a reason for hiding this comment

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

안녕하세요 코치 Flynn입니다 😀
정말 사소한 건데요, 복잡도 분석에 관한 주석을 코드 위쪽으로 옮겨주시면 리뷰어들이 리뷰하기 조금 더 편합니다

Copy link
Contributor Author

@taewanseoul taewanseoul Dec 23, 2024

Choose a reason for hiding this comment

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

오 좋은 팁 감사합니다!

Loading