From 63dac45956a5f1661c09549f8c26b1a6968288e2 Mon Sep 17 00:00:00 2001 From: Esther <181283957+EstherKim97@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:06:51 -0800 Subject: [PATCH 1/8] contains duplicate solution --- contains-duplicate/EstherKim97.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 contains-duplicate/EstherKim97.py diff --git a/contains-duplicate/EstherKim97.py b/contains-duplicate/EstherKim97.py new file mode 100644 index 000000000..60dad6f0c --- /dev/null +++ b/contains-duplicate/EstherKim97.py @@ -0,0 +1,9 @@ +# 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 \ No newline at end of file From a9af1981ee03323d1f7c8984a302a63d25c8fb4e Mon Sep 17 00:00:00 2001 From: Esther <181283957+EstherKim97@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:40:52 -0800 Subject: [PATCH 2/8] Valid palindrome --- valid-palindrome/EstherKim97.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 valid-palindrome/EstherKim97.py diff --git a/valid-palindrome/EstherKim97.py b/valid-palindrome/EstherKim97.py new file mode 100644 index 000000000..4accf4e50 --- /dev/null +++ b/valid-palindrome/EstherKim97.py @@ -0,0 +1,11 @@ +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 From 389d6b8fb85d66997fc30d95c07eeb38efc0958b Mon Sep 17 00:00:00 2001 From: Esther <181283957+EstherKim97@users.noreply.github.com> Date: Fri, 13 Dec 2024 23:17:14 -0800 Subject: [PATCH 3/8] top k frequent element --- top-k-frequent-elements/EstherKim97.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 top-k-frequent-elements/EstherKim97.py diff --git a/top-k-frequent-elements/EstherKim97.py b/top-k-frequent-elements/EstherKim97.py new file mode 100644 index 000000000..54821d78e --- /dev/null +++ b/top-k-frequent-elements/EstherKim97.py @@ -0,0 +1,17 @@ +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]] + + #nums.count(i) From bfc2cb1b40033b91ce772943b18319d238232784 Mon Sep 17 00:00:00 2001 From: Esther <181283957+EstherKim97@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:54:25 -0800 Subject: [PATCH 4/8] update --- top-k-frequent-elements/EstherKim97.py | 1 + 1 file changed, 1 insertion(+) diff --git a/top-k-frequent-elements/EstherKim97.py b/top-k-frequent-elements/EstherKim97.py index 54821d78e..ebea89889 100644 --- a/top-k-frequent-elements/EstherKim97.py +++ b/top-k-frequent-elements/EstherKim97.py @@ -15,3 +15,4 @@ def topKFrequent(self, nums, k): return [x[1] for x in data[:k]] #nums.count(i) + From 2a015b542f97b237e462e0a5ad882899153c0df9 Mon Sep 17 00:00:00 2001 From: Esther <181283957+EstherKim97@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:55:13 -0800 Subject: [PATCH 5/8] update --- contains-duplicate/EstherKim97.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contains-duplicate/EstherKim97.py b/contains-duplicate/EstherKim97.py index 60dad6f0c..e88ccb839 100644 --- a/contains-duplicate/EstherKim97.py +++ b/contains-duplicate/EstherKim97.py @@ -6,4 +6,5 @@ def containsDuplicate(nums): if num in seen: return True seen.add(num) - return False \ No newline at end of file + return False + From 79680f380661c447ff8b58df098efdfcbe07d58f Mon Sep 17 00:00:00 2001 From: Esther <181283957+EstherKim97@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:58:58 -0800 Subject: [PATCH 6/8] update --- valid-palindrome/EstherKim97.py | 1 + 1 file changed, 1 insertion(+) diff --git a/valid-palindrome/EstherKim97.py b/valid-palindrome/EstherKim97.py index 4accf4e50..4630ab127 100644 --- a/valid-palindrome/EstherKim97.py +++ b/valid-palindrome/EstherKim97.py @@ -9,3 +9,4 @@ def isPalindrome(self, s): if s[i] != s[-(i+1)]: return False return True + From 8f0d275cf06d0f1e7526311f294fb412121c3b47 Mon Sep 17 00:00:00 2001 From: Esther <181283957+EstherKim97@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:01:18 -0800 Subject: [PATCH 7/8] updatE --- top-k-frequent-elements/EstherKim97.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/top-k-frequent-elements/EstherKim97.py b/top-k-frequent-elements/EstherKim97.py index ebea89889..a1a3e8ad0 100644 --- a/top-k-frequent-elements/EstherKim97.py +++ b/top-k-frequent-elements/EstherKim97.py @@ -13,6 +13,4 @@ def topKFrequent(self, nums, k): data = sorted(data, reverse=True, key=lambda x:[1]) return [x[1] for x in data[:k]] - - #nums.count(i) - + \ No newline at end of file From f445f712f26cfc5e57da3a1d6634aebb6ea9b087 Mon Sep 17 00:00:00 2001 From: Esther <181283957+EstherKim97@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:03:23 -0800 Subject: [PATCH 8/8] update --- top-k-frequent-elements/EstherKim97.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/top-k-frequent-elements/EstherKim97.py b/top-k-frequent-elements/EstherKim97.py index a1a3e8ad0..cef0b6cd7 100644 --- a/top-k-frequent-elements/EstherKim97.py +++ b/top-k-frequent-elements/EstherKim97.py @@ -13,4 +13,4 @@ def topKFrequent(self, nums, k): data = sorted(data, reverse=True, key=lambda x:[1]) return [x[1] for x in data[:k]] - \ No newline at end of file +