Files
second-brain/practice/LeetCode/Solutions/0001-two-sum.py
T
kiskaadee ff59aa44af
Brain Structural Validation / Validate Markdown Structure & Links (push) Failing after 4s
refactor(practice): modernize type annotations and fix ruff linting in LeetCode solutions
- Update typing.List to built-in list[T]
- Annotate SYMBOLS dictionary with ClassVar in 0013-roman-to-integer
- Combine nested if conditions in 0028 and 0058 solutions
2026-09-10 08:55:56 -05:00

20 lines
522 B
Python

class Solution:
def twoSum(self, nums: list[int], target: int) -> list[int]:
seen = {}
for i, x in enumerate(nums):
y = target - x
if y in seen:
return [i, seen[y]]
seen[x] = i
return []
def brute_force(self, nums: list[int], target: int) -> list[int]:
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
if nums[i] + nums[j] == target:
return [i, j]
return []