diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000..b5b515db3a Binary files /dev/null and b/.DS_Store differ 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