Question
Two Sum Given a list of integers and an integer target, write a function that takes the list and the target and returns a new
Two Sum
Given a list of integers and an integer target, write a function that takes the list and the target and returns a new list of indices of any two numbers in the list such that they add up to target.
You may assume that each input will have exactly one solution, and you are not allowed to use the same element at a given index twice.
You may return the list with indices in any order.
Example 1:
Input: numbers = [1, 2, 5, 4, 10], target = 15
Output: [2, 4]
Explanation: numbers[2] = 5 and numbers[4] = 10, which can be added to the target integer, 15.[4, 2] is also acceptable.
Example 2:
Input: numbers = [1, 1] , target = 2
Output: [0, 1]
Example:
Input: numbers = [1, 2, 3], target = 5
Output: [1, 2]
Explanation: numbers[1] + numbers[2] = 2 + 3 = 5
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started