Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions contains-duplicate/dm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from typing import List


class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
return len(nums) != len(set(nums))
6 changes: 6 additions & 0 deletions number-of-1-bits/dm.py
Copy link
Contributor

Choose a reason for hiding this comment

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

나머지 문제를 다 푸신후, 해당 문제를 O(n)으로 푸는 방법도 고민해보시면 좋을 것 같습니다 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

코멘트 감사합니다! 🙏
지금 당장 떠오르는 방법은 없지만, 좀 고민해볼게요... 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

혹시 이진연산에 대해서 배운적 있으실까요? 해당 방법으로 문제를 푼다면 해결하실 수 있을겁니다 😄

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:
def hammingWeight(self, n: int, acc: int = 0) -> int:
if n == 0:
return acc

return self.hammingWeight(n // 2, acc + n % 2)
21 changes: 21 additions & 0 deletions top-k-frequent-elements/dm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import List


class Solution:
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
count_dict = {}
frequency_bucket = [[] for i in range(len(nums) + 1)]
result = []

for num in nums:
count_dict[num] = count_dict.get(num, 0) + 1

for num, count in count_dict.items():
frequency_bucket[count].append(num)

for i in range(len(frequency_bucket) - 1, 0, -1):
for num in frequency_bucket[i]:
result.append(num)

if len(result) == k:
return result