diff --git a/python3/1/a.py b/python3/1/a.py index 3a581bb..6c5936e 100644 --- a/python3/1/a.py +++ b/python3/1/a.py @@ -5,8 +5,10 @@ class Solution: def twoSum(self, nums: list[int], target: int) -> list[int]: - n = len(nums) + n: int = len(nums) + i: int + j: int # enumerate does not allow the last item to be skipped without slicing, # which would require linear auxiliary space. for i in range(n - 1): diff --git a/python3/1/b.py b/python3/1/b.py index cbfcbb2..6391235 100644 --- a/python3/1/b.py +++ b/python3/1/b.py @@ -5,10 +5,12 @@ class Solution: def twoSum(self, nums: list[int], target: int) -> list[int]: - i = 0 - j = len(nums) - 1 - snums = sorted(nums) + snums: list[int] = sorted(nums) + i: int = 0 + j: int = len(nums) - 1 + total: int + res: list[int] while i < j: total = snums[i] + snums[j] if total == target: diff --git a/python3/1/c.py b/python3/1/c.py index 2b7e751..f4b7628 100644 --- a/python3/1/c.py +++ b/python3/1/c.py @@ -5,8 +5,11 @@ class Solution: def twoSum(self, nums: list[int], target: int) -> list[int]: - visited = {} + visited: dict[int, int] = {} + i: int + num: int + diff: int for i, num in enumerate(nums): diff = target - num if diff in visited: diff --git a/python3/217/a.py b/python3/217/a.py index a1b8c31..6afbd28 100644 --- a/python3/217/a.py +++ b/python3/217/a.py @@ -5,10 +5,12 @@ class Solution: def containsDuplicate(self, nums: list[int]) -> bool: - n = len(nums) + n: int = len(nums) if n < 2: return False + i: int + j: int # enumerate does not allow the last item to be skipped without slicing, # which would require linear auxiliary space. for i in range(n - 1): diff --git a/python3/217/b.py b/python3/217/b.py index 8550fc8..b190749 100644 --- a/python3/217/b.py +++ b/python3/217/b.py @@ -10,6 +10,8 @@ def containsDuplicate(self, nums: list[int]) -> bool: nums.sort() + i: int + num: int for i, num in enumerate(nums): # nums[0] is needlessly compared to nums[-1] so as to avoid # checking if i > 0 at every iteration. diff --git a/python3/217/c.py b/python3/217/c.py index 0ed644f..d7dea5c 100644 --- a/python3/217/c.py +++ b/python3/217/c.py @@ -8,8 +8,9 @@ def containsDuplicate(self, nums: list[int]) -> bool: if len(nums) < 2: return False - visited = set() + visited: set[int] = set() + num: int for num in nums: if num in visited: return True diff --git a/python3/242/b.py b/python3/242/b.py index 036ccc3..6fd02ba 100644 --- a/python3/242/b.py +++ b/python3/242/b.py @@ -8,8 +8,10 @@ def isAnagram(self, s: str, t: str) -> bool: if len(s) != len(t): return False - count = {} + count: dict[str, int] = {} + i: int + c: str for i, c in enumerate(s): count[c] = count.get(c, 0) + 1 count[t[i]] = count.get(t[i], 0) - 1