Skip to content

Commit e0d7d23

Browse files
authored
Merge pull request #695 from EstherKim97/main
[EstherKim97] Week 1
2 parents 0f61364 + f445f71 commit e0d7d23

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

contains-duplicate/EstherKim97.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# 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.
2+
3+
def containsDuplicate(nums):
4+
seen = set()
5+
for num in nums:
6+
if num in seen:
7+
return True
8+
seen.add(num)
9+
return False
10+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution(object):
2+
def topKFrequent(self, nums, k):
3+
unique_no = set(nums)
4+
data = []
5+
6+
for i in unique_no:
7+
count = 0
8+
for j in nums:
9+
if i == j:
10+
count += 1
11+
data.append((count, i))
12+
13+
data = sorted(data, reverse=True, key=lambda x:[1])
14+
15+
return [x[1] for x in data[:k]]
16+

valid-palindrome/EstherKim97.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution(object):
2+
def isPalindrome(self, s):
3+
import re
4+
# remove all non-alphanumeric characters
5+
s = re.sub(r'\W+', '', s.lower())
6+
7+
# check if the string is equal forward and backward
8+
for i in range(len(s)//2):
9+
if s[i] != s[-(i+1)]:
10+
return False
11+
return True
12+

0 commit comments

Comments
 (0)