From 786a470dea495b29daf3d53d54cbe9709166d614 Mon Sep 17 00:00:00 2001 From: Sam2022moon <104721736+Sam2022moon@users.noreply.github.com> Date: Tue, 23 Apr 2024 03:37:35 +0900 Subject: [PATCH] first commit --- .DS_Store | Bin 0 -> 6148 bytes sam_lee/Contains_Duplicate.py | 10 ++++++++++ sam_lee/Two_Sum | 10 ++++++++++ sam_lee/Valid_Anagram | 18 ++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 .DS_Store create mode 100644 sam_lee/Contains_Duplicate.py create mode 100644 sam_lee/Two_Sum create mode 100644 sam_lee/Valid_Anagram diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b5b515db3ac59bee5cd339b4ceec9138f3b6efc9 GIT binary patch literal 6148 zcmeHK%}T>S5T0$TO({YT3OxqA7OZV4h?h|73mDOZN=!)5V45vWYY(N6v%Zi|;`2DO zy8){?coMNQu=~x<&u->}><<8l(IPwsXaRtQjZlzMB4jRgRZK9UP;(>@K@=>rX^@mm z^cPL^?RCh&hY5J_>HB4Xp0{9{#M!*teHWE#ZD+S`)vcy==RV4%JNM^{Y~;^wXmlxM z5)`^0T*cASYwe%ObneG#G*bz27-7imb)1HBIg*Ps%v7$c9ah6?c&+wo)f;v@c7HHj zckIu2F3r*wOWw{53)n)afljXd844<{Ht1 zB6KREP8H^fA#^(0Z4>7h%r)wC5Nc(d$E;jDUW8g5?Y0UB;b`QZ8DIuB8K~-Ei_ZUZ z{AEfX`I{*`Vg{Ijf5w2QjotAGi!x{HxAN$$wXxk}BcZsQ6cp4qE&({8eWb0N+HaGN ZagM=UBh5l~m5#_40YwOR%)l=&@ByFuOj-Z{ literal 0 HcmV?d00001 diff --git a/sam_lee/Contains_Duplicate.py b/sam_lee/Contains_Duplicate.py new file mode 100644 index 0000000000..0ac7e3aeed --- /dev/null +++ b/sam_lee/Contains_Duplicate.py @@ -0,0 +1,10 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + my_dict = {} + + for num in nums: + if num in my_dict: + return True + my_dict[num] = 0 + + return False \ No newline at end of file diff --git a/sam_lee/Two_Sum b/sam_lee/Two_Sum new file mode 100644 index 0000000000..d2be88998c --- /dev/null +++ b/sam_lee/Two_Sum @@ -0,0 +1,10 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + my_dict = {} + + for i in range(len(nums)): + complement = target - nums[i] + if complement in my_dict: + return [my_dict[complement], i] + + my_dict[nums[i]] = i \ No newline at end of file diff --git a/sam_lee/Valid_Anagram b/sam_lee/Valid_Anagram new file mode 100644 index 0000000000..8f4adf175a --- /dev/null +++ b/sam_lee/Valid_Anagram @@ -0,0 +1,18 @@ +# Time Complexity : O(nlog(n)) +# Space Complexity : 0(1) +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + return sorted(s) == sorted(t) + +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + my_dict1 = {} + my_dict2 = {} + + for char in s: + my_dict1[char] = my_dict1.get(char, 0) + 1 + + for char in t: + my_dict2[char] = my_dict2.get(char, 0) + 1 + + return my_dict1 == my_dict2 \ No newline at end of file