diff --git a/Soohyeun/2024-09-23-IsAnagram.py b/Soohyeun/2024-09-23-IsAnagram.py new file mode 100644 index 00000000..1fc3274c --- /dev/null +++ b/Soohyeun/2024-09-23-IsAnagram.py @@ -0,0 +1,18 @@ +from collections import defaultdict + + +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + if len(s) != len(t): + return False + + seen = defaultdict(int) + for i in range(len(s)): + seen[s[i]] += 1 + seen[t[i]] -= 1 + if seen[s[i]] == 0: + del seen[s[i]] + if seen[t[i]] == 0: + del seen[t[i]] + + return True if not seen else False diff --git a/Soohyeun/2024-09-23-TwoIntegerSum.py b/Soohyeun/2024-09-23-TwoIntegerSum.py new file mode 100644 index 00000000..add764c0 --- /dev/null +++ b/Soohyeun/2024-09-23-TwoIntegerSum.py @@ -0,0 +1,9 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + seen = dict() + for index, num in enumerate(nums): + rest = target - num + if rest in seen.keys(): + return [seen[rest], index] + seen[num] = index + return -1 \ No newline at end of file diff --git a/Soohyeun/2024-09-26-DuplicateInteger.py b/Soohyeun/2024-09-26-DuplicateInteger.py new file mode 100644 index 00000000..e9dd3888 --- /dev/null +++ b/Soohyeun/2024-09-26-DuplicateInteger.py @@ -0,0 +1,5 @@ +class Solution: + def hasDuplicate(self, nums: List[int]) -> bool: + set_num = set(nums) + + return False if len(set_num) == len(nums) else True