Given an array of integers, return the indices of the two numbers that add up to a…
- User
Given an array of integers, return the indices of the two numbers that add up to a specific target. Please solve using the most optimal algorithm possible.
Assistant
def two_sum(nums, target): seen = {} for i, num in enumerate(nums): complement = target - num if complement in seen: return [seen[complement], i] seen[num] = i return []Would you like me to explain or break down this code?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.