Two Sum (Rust)
Source: LeetCode #1
Topics: array, hash map
Problem
Given a vector of integers nums and an integer target, return the indices of the two numbers
that add up to target.
- Each input has exactly one solution.
- You may not use the same element twice.
- Return the indices in any order.
two_sum(vec![2, 7, 11, 15], 9) // -> [0, 1]
two_sum(vec![3, 2, 4], 6) // -> [1, 2]
Grading
Your solution.rs is compiled together with a trusted tests.rs (which include!s your file)
using rustc --test. Only solution.rs is yours to edit.
Sign in to submit your solution.