Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions contains-duplicate/jun-brro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Solution(object):
def containsDuplicate(self, nums):
return len(set(nums))!=len(nums)
21 changes: 21 additions & 0 deletions top-k-frequent-elements/jun-brro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution(object):
def topKFrequent(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: List[int]
"""
freq = {}
for n in nums:
freq[n] = freq.get(n, 0) + 1

buckets = [[] for _ in range(len(nums) + 1)]
for num, count in freq.items():
buckets[count].append(num)

result = []
for count in range(len(nums), 0, -1):
for num in buckets[count]:
result.append(num)
if len(result) == k:
return result
6 changes: 6 additions & 0 deletions two-sum/jun-brro.py
Copy link
Contributor

Choose a reason for hiding this comment

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

해시맵을 쓰면 이중 for문 방식과 비교해봤을 때 시간복잡도를 O(n^2)에서 O(n)으로 개선할 수 있지만 공간복잡도는 O(1)에서 O(n)으로 늘어 난다고 합니다! 상황 따라서 선택 하면 될 것 같아요😀
해시맵 풀이법 링크 첨부드립니다!https://leetcode.com/problems/two-sum/editorial

Copy link
Contributor 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,6 @@
class Solution(object):
def twoSum(self, nums, target):
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
if nums[i] + nums[j] == target:
return [i, j]