Skip to content

[EstherKim97] Week 1 #695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 18, 2024
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
10 changes: 10 additions & 0 deletions contains-duplicate/EstherKim97.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

def containsDuplicate(nums):
seen = set()
for num in nums:
if num in seen:
return True
seen.add(num)
return False

16 changes: 16 additions & 0 deletions top-k-frequent-elements/EstherKim97.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution(object):
def topKFrequent(self, nums, k):
unique_no = set(nums)
data = []

for i in unique_no:
count = 0
for j in nums:
if i == j:
count += 1
data.append((count, i))

data = sorted(data, reverse=True, key=lambda x:[1])

return [x[1] for x in data[:k]]

12 changes: 12 additions & 0 deletions valid-palindrome/EstherKim97.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution(object):
def isPalindrome(self, s):
import re
# remove all non-alphanumeric characters
s = re.sub(r'\W+', '', s.lower())

# check if the string is equal forward and backward
for i in range(len(s)//2):
if s[i] != s[-(i+1)]:
return False
return True

Loading