Brain Structural Validation / Validate Markdown Structure & Links (push) Failing after 4s
- 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
20 lines
522 B
Python
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 []
|