Skip to content

Commit a196c11

Browse files
committed
new commit
1 parent 979f856 commit a196c11

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

two-sum/hongseoupyun.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
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+
#
17
class Solution:
28
def twoSum(self, nums: List[int], target: int) -> List[int]:
39
seen = {}

two-sum/hongseoupyun.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
//
7+
8+
function twoSum2(nums: number[], target: number): number[] {
9+
const seen:{[key:number] : number} = {};
10+
for (let i = 0; i<nums.length; i++){
11+
let complement = target - nums[i]
12+
if (complement in seen) {
13+
return [seen[complement],i]
14+
}
15+
seen[nums[i]] = i
16+
}
17+
return []
18+
};

0 commit comments

Comments
 (0)