Skip to content
Open
10 changes: 10 additions & 0 deletions contains-duplicate/daiyongg-kim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
my_set = set()

for num in nums:
if num in my_set:
return True
my_set.add(num)
return False

13 changes: 13 additions & 0 deletions longest-consecutive-sequence/daiyongg-kim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
def longestConsecutive(self, nums: List[int]) -> int:
my_set = set(nums)
longest = 0
length = 1
for num in my_set:
if num - 1 not in my_set:
length = 1
while num + length in my_set:
length += 1
longest = max (longest, length)

return longest
16 changes: 16 additions & 0 deletions top-k-frequent-elements/daiyongg-kim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution:
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
counts = Counter(nums)

items = counts.items()

sort_by_value = sorted(
items,
key=lambda item: item[1],
reverse = True
)
result = []
for i in range(k):
result.append(sort_by_value[i][0])
return result

10 changes: 10 additions & 0 deletions two-sum/daiyongg-kim.py

Choose a reason for hiding this comment

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

투포인터는 이렇게 간단하게 풀 수도 있겠네요 잘 봤습니다!

Copy link
Author

Choose a reason for hiding this comment

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

워낙 많이 풀어본거라, 짧게 만들려고 한거라서요.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
hash_map = {}
for i, num in enumerate(nums):
current = target - num
if current in hash_map:
return [hash_map[current], i]
hash_map[num] = i
return []