Skip to content

Commit f027594

Browse files
committed
refactor: improve comments for clarity and consistency in twoSum implementations
1 parent a196c11 commit f027594

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

two-sum/hongseoupyun.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# For each numbers in given array, calculate complement (target - num)
44
# If complement is in hash table(seen), return array of index of the currnet number and index of complement in hash table(seen)
55
# If complement is not in has table(seen), store the current number in hash table(seen) and continue checking the numbers
6-
#
6+
# The algorithm uses a single loop that goes through each element in nums exactly one time.
7+
# If the array contains n elements, the loop runs n times → O(n).
78
class Solution:
89
def twoSum(self, nums: List[int], target: int) -> List[int]:
910
seen = {}
@@ -13,4 +14,3 @@ def twoSum(self, nums: List[int], target: int) -> List[int]:
1314
return [seen[complement], i]
1415
seen[num] = i
1516
return []
16-

two-sum/hongseoupyun.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// # Create a empty hash table(seen) and store numbers as a key and their indices as a value
2-
// # Iterate through the given array(nums)
3-
// # For each numbers in given array, calculate complement (target - num)
4-
// # If complement is in hash table(seen), return array of index of the currnet number and index of complement in hash table(seen)
5-
// # If complement is not in has table(seen), store the current number in hash table(seen) and continue checking the numbers
6-
//
1+
// Create a empty hash table(seen) and store numbers as a key and their indices as a value
2+
// Iterate through the given array(nums)
3+
// For each numbers in given array, calculate complement (target - num)
4+
// If complement is in hash table(seen), return array of index of the currnet number and index of complement in hash table(seen)
5+
// If complement is not in has table(seen), store the current number in hash table(seen) and continue checking the numbers
6+
// The algorithm uses a single loop that goes through each element in nums exactly one time.
7+
// If the array contains n elements, the loop runs n times → O(n).
78

89
function twoSum2(nums: number[], target: number): number[] {
910
const seen:{[key:number] : number} = {};

0 commit comments

Comments
 (0)