diff --git a/two-sum/DaleSeo-test.py b/two-sum/DaleSeo-test.py new file mode 100644 index 0000000000..2d71c22e4f --- /dev/null +++ b/two-sum/DaleSeo-test.py @@ -0,0 +1,10 @@ +# TC: O(n) +# SC: O(n) +class Solution: + def twoSum(self, nums: list[int], target: int) -> list[int]: + seen = {} + for i, num in enumerate(nums): + if target - num in seen: + return [seen[target - num], i] + seen[num] = i + return [] diff --git a/valid-parentheses/DaleSeo-test.py b/valid-parentheses/DaleSeo-test.py new file mode 100644 index 0000000000..fb1e865229 --- /dev/null +++ b/valid-parentheses/DaleSeo-test.py @@ -0,0 +1,13 @@ +# TC: O(n) +# SC: O(n) +class Solution: + def isValid(self, s: str) -> bool: + pairs = {")": "(", "]": "[", "}": "{"} + stack = [] + for ch in s: + if ch in pairs: + if not stack or stack.pop() != pairs[ch]: + return False + else: + stack.append(ch) + return not stack