From 53d44a664a968eeeecbcda57fcc410a23ef876a9 Mon Sep 17 00:00:00 2001 From: Hongseoup Yun Date: Wed, 5 Nov 2025 21:28:37 -0500 Subject: [PATCH 1/5] hongseoupyun_two_sum_solution --- two-sum/hongseoupyun.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 two-sum/hongseoupyun.py diff --git a/two-sum/hongseoupyun.py b/two-sum/hongseoupyun.py new file mode 100644 index 000000000..9cb8363fa --- /dev/null +++ b/two-sum/hongseoupyun.py @@ -0,0 +1,9 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + seen = {} + for i, num in enumerate(nums): + complement = target - num + if complement in seen: + return [seen[complement], i] + seen[num] = i + return [] \ No newline at end of file From 979f8563b7f51fc52f98ce89bf377d387df37a66 Mon Sep 17 00:00:00 2001 From: Hongseoup Yun Date: Wed, 5 Nov 2025 21:35:53 -0500 Subject: [PATCH 2/5] add line break --- two-sum/hongseoupyun.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/two-sum/hongseoupyun.py b/two-sum/hongseoupyun.py index 9cb8363fa..ae73f7e3d 100644 --- a/two-sum/hongseoupyun.py +++ b/two-sum/hongseoupyun.py @@ -6,4 +6,5 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: if complement in seen: return [seen[complement], i] seen[num] = i - return [] \ No newline at end of file + return [] + \ No newline at end of file From a196c1109260dbf1b90e84c2333271edf5422306 Mon Sep 17 00:00:00 2001 From: Hongseoup Yun Date: Thu, 13 Nov 2025 20:23:18 -0500 Subject: [PATCH 3/5] new commit --- two-sum/hongseoupyun.py | 6 ++++++ two-sum/hongseoupyun.ts | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 two-sum/hongseoupyun.ts diff --git a/two-sum/hongseoupyun.py b/two-sum/hongseoupyun.py index ae73f7e3d..1fe69a08a 100644 --- a/two-sum/hongseoupyun.py +++ b/two-sum/hongseoupyun.py @@ -1,3 +1,9 @@ +# Create a empty hash table(seen) and store numbers as a key and their indices as a value +# Iterate through the given array(nums) +# For each numbers in given array, calculate complement (target - num) +# If complement is in hash table(seen), return array of index of the currnet number and index of complement in hash table(seen) +# If complement is not in has table(seen), store the current number in hash table(seen) and continue checking the numbers +# class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: seen = {} diff --git a/two-sum/hongseoupyun.ts b/two-sum/hongseoupyun.ts new file mode 100644 index 000000000..c4f014e29 --- /dev/null +++ b/two-sum/hongseoupyun.ts @@ -0,0 +1,18 @@ +// # Create a empty hash table(seen) and store numbers as a key and their indices as a value +// # Iterate through the given array(nums) +// # For each numbers in given array, calculate complement (target - num) +// # If complement is in hash table(seen), return array of index of the currnet number and index of complement in hash table(seen) +// # If complement is not in has table(seen), store the current number in hash table(seen) and continue checking the numbers +// + +function twoSum2(nums: number[], target: number): number[] { + const seen:{[key:number] : number} = {}; + for (let i = 0; i Date: Fri, 14 Nov 2025 16:50:44 -0500 Subject: [PATCH 4/5] refactor: improve comments for clarity and consistency in twoSum implementations --- two-sum/hongseoupyun.py | 4 ++-- two-sum/hongseoupyun.ts | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/two-sum/hongseoupyun.py b/two-sum/hongseoupyun.py index 1fe69a08a..2f2c7f773 100644 --- a/two-sum/hongseoupyun.py +++ b/two-sum/hongseoupyun.py @@ -3,7 +3,8 @@ # For each numbers in given array, calculate complement (target - num) # If complement is in hash table(seen), return array of index of the currnet number and index of complement in hash table(seen) # If complement is not in has table(seen), store the current number in hash table(seen) and continue checking the numbers -# +# The algorithm uses a single loop that goes through each element in nums exactly one time. +# If the array contains n elements, the loop runs n times → O(n). class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: seen = {} @@ -13,4 +14,3 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: return [seen[complement], i] seen[num] = i return [] - \ No newline at end of file diff --git a/two-sum/hongseoupyun.ts b/two-sum/hongseoupyun.ts index c4f014e29..077645ee9 100644 --- a/two-sum/hongseoupyun.ts +++ b/two-sum/hongseoupyun.ts @@ -1,9 +1,10 @@ -// # Create a empty hash table(seen) and store numbers as a key and their indices as a value -// # Iterate through the given array(nums) -// # For each numbers in given array, calculate complement (target - num) -// # If complement is in hash table(seen), return array of index of the currnet number and index of complement in hash table(seen) -// # If complement is not in has table(seen), store the current number in hash table(seen) and continue checking the numbers -// +// Create a empty hash table(seen) and store numbers as a key and their indices as a value +// Iterate through the given array(nums) +// For each numbers in given array, calculate complement (target - num) +// If complement is in hash table(seen), return array of index of the currnet number and index of complement in hash table(seen) +// If complement is not in has table(seen), store the current number in hash table(seen) and continue checking the numbers +// The algorithm uses a single loop that goes through each element in nums exactly one time. +// If the array contains n elements, the loop runs n times → O(n). function twoSum2(nums: number[], target: number): number[] { const seen:{[key:number] : number} = {}; From 10b2e9ea5112d666e0050d78d2a1c2d753950f2e Mon Sep 17 00:00:00 2001 From: Hongseoup Yun Date: Fri, 14 Nov 2025 16:53:44 -0500 Subject: [PATCH 5/5] refactor: improve comment formatting and clarity time/space complexity in twoSum implementations --- two-sum/hongseoupyun.py | 5 +++++ two-sum/hongseoupyun.ts | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/two-sum/hongseoupyun.py b/two-sum/hongseoupyun.py index 2f2c7f773..482985e72 100644 --- a/two-sum/hongseoupyun.py +++ b/two-sum/hongseoupyun.py @@ -5,6 +5,11 @@ # If complement is not in has table(seen), store the current number in hash table(seen) and continue checking the numbers # The algorithm uses a single loop that goes through each element in nums exactly one time. # If the array contains n elements, the loop runs n times → O(n). +# We use a hash table (seen) to store numbers we've already visited. +# seen could contain up to n − 1 entries, so its size grows linearly with input size → O(n). + + + class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: seen = {} diff --git a/two-sum/hongseoupyun.ts b/two-sum/hongseoupyun.ts index 077645ee9..5da130efc 100644 --- a/two-sum/hongseoupyun.ts +++ b/two-sum/hongseoupyun.ts @@ -1,3 +1,6 @@ +/* + + // Create a empty hash table(seen) and store numbers as a key and their indices as a value // Iterate through the given array(nums) // For each numbers in given array, calculate complement (target - num) @@ -5,6 +8,11 @@ // If complement is not in has table(seen), store the current number in hash table(seen) and continue checking the numbers // The algorithm uses a single loop that goes through each element in nums exactly one time. // If the array contains n elements, the loop runs n times → O(n). + We use a hash table (seen) to store numbers we've already visited. + seen could contain up to n − 1 entries, so its size grows linearly with input size → O(n). + + +*/ function twoSum2(nums: number[], target: number): number[] { const seen:{[key:number] : number} = {};